-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3.cpp
More file actions
34 lines (32 loc) · 764 Bytes
/
Copy path3.cpp
File metadata and controls
34 lines (32 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
using namespace std;
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int arr[256];
int maxlen = 0;
for(int i = 0; i < s.length(); i++) {
memset(arr, 0, sizeof(arr));
int j = i;
for(; j < s.length(); j++) {
if(arr[s[j]] != 0)
break;
arr[s[j]]++;
}
if(j - i > maxlen)
maxlen = j - i;
}
return maxlen;
}
};
int main() {
Solution s;
string str = "";
cout << s.lengthOfLongestSubstring(str) << endl;
while(cin >> str){
cout << s.lengthOfLongestSubstring(str) << endl;
}
}