Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <climits>
- using namespace std;
- const int MAX_CHARS=10001;
- string str;
- string findSubString(string str)
- {
- int n=str.length();
- int dist_count=0;
- bool visited[MAX_CHARS]={false};
- for(int i=0;i<n;++i)
- if(visited[(int)str[i]]==false)
- visited[(int)str[i]]=true,++dist_count;
- int start=0,start_index=-1,min_len=INT_MAX;
- int countc=0;
- int curr_count[MAX_CHARS]={0};
- for(int j=0;j<n;++j)
- {
- ++curr_count[(int)str[j]];
- if(curr_count[(int)str[j]]==1)
- ++countc;
- if(countc==dist_count)
- {
- while(curr_count[(int)str[start]]>1)
- {
- if(curr_count[(int)str[start]]>1)
- --curr_count[(int)str[start]];
- ++start;
- }
- int len_window=j-start+1;
- if(min_len>len_window)
- min_len=len_window,start_index=start;
- }
- }
- return str.substr(start_index,min_len);
- }
- int main()
- {
- cin>>str;
- str=findSubString(str);
- cout<<str.length();
- return 0;
- }
Add Comment
Please, Sign In to add comment