Skip to content

Commit d2691e1

Browse files
authored
Merge pull request kothariji#423 from Sparty-v6/master
Added problem 3 of leetcode TOP
2 parents 87bdbd2 + 3ed5117 commit d2691e1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
#define IO() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
4+
5+
int lengthOfLongestSubstring(string str) {
6+
int left = 0;
7+
int right = 0;
8+
int maxx = 0;
9+
10+
set<char> s;
11+
12+
while(right < str.size()){
13+
if( s.find(str[right]) == s.end() ) {
14+
s.insert(str[right]);
15+
right++;
16+
int size = s.size();
17+
maxx = std::max(size,maxx);
18+
}
19+
else{
20+
s.erase(str[left]);
21+
left++;
22+
}
23+
}
24+
return maxx;
25+
}
26+
27+
int main(){
28+
29+
IO();
30+
31+
string s = "abcabcbb";
32+
cout<<lengthOfLongestSubstring(s);
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)