-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03.cpp
More file actions
44 lines (32 loc) · 709 Bytes
/
Copy path03.cpp
File metadata and controls
44 lines (32 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<bits/stdc++.h>
#include<String.h>
#include<iostream>
using namespace std;
int lengthOfLongestSubstring(string s) {
if( s.length() == 0) return 0;
map<char,int> map;
int max_len = 0,pre = -1;
for(int i = 0;i<s.length();i++)
{
map[s[i]] = -1;
}
for (int i = 0;i<s.length();i++)
{
pre = max(pre,map[s[i]]);
max_len = max(max_len,i-pre);
map[s[i]] = i;
for(int i = 0;i<s.length();i++)
{
cout<< s[i] <<" "<<map[s[i]]<<" "<<flush;
}
cout<<endl;
}
return max_len;
}
int main()
{
string s;
cin>>s;
cout<<lengthOfLongestSubstring(s);
cout<<"hello";
}