forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
30 lines (30 loc) · 709 Bytes
/
solution.cpp
File metadata and controls
30 lines (30 loc) · 709 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
class Solution
{
public:
int lengthOfLongestSubstring(string s)
{
int left=0, right=0;
int maxLength=0, length=0;
vector<bool> flag(255,false);
for(;right<s.size();right++)
{
if(flag[s[right]] == true)
{
for(;s[left] != s[right];left++)
{
flag[s[left]] = false;
length --;
}
left++;
}
else
{
flag[s[right]] = true;
length++;
if(length > maxLength)
maxLength = length;
}
}
return maxLength;
}
};