-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniqueSubStrings.cpp
51 lines (48 loc) · 1.1 KB
/
UniqueSubStrings.cpp
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
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
int uniqueSubstrings(string input)
{
int maxLength = INT_MIN;
int length = 0;
unordered_map<char, int> m;
unordered_map<char, int>::iterator it;
for (int i = 0; i < (int)input.size(); i++)
{
if (m.find(input[i]) != m.end() && m[input[i]] != 0)
{
if (length > maxLength)
{
maxLength = length;
}
i = i-length+1;;
length = 0;
for (it = m.begin(); it != m.end(); it++)
{
it->second = 0;
}
cout<<endl<<endl;
}
if (m[input[i]] == 0)
{
prev = i;
length++;
m[input[i]]++;
cout<<input[i];
}
if ((m.find(input[i]) == m.end()))
{
m.insert(make_pair(input[i], 1));
length++;
cout<<input[i];
}
}
if(maxLength == INT_MIN){
return length;
}
return maxLength;
}
int main()
{
cout << uniqueSubstrings("kfsmygpcwzvueiaqxjnhdoblrt");
return 0;
}