-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For every letter looks how far it can go without repeating using previus resoults
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <iostream> | ||
|
||
int count [257]; | ||
|
||
std::string findLargestSubstr(const std::string &str){ | ||
// start of current substr, and end of current substr | ||
int s = 0, e = 0; | ||
int maxs=0, maxe=0; | ||
|
||
while (s < str.size()){ | ||
while (count[str[e]] == 0 && e < str.size()){ | ||
count[str[e]] ++; | ||
e++; | ||
} | ||
if (e-s > maxe - maxs){ | ||
maxs = s; | ||
maxe = e; | ||
} | ||
count[str[s]] --; | ||
s++; | ||
} | ||
|
||
return str.substr(maxs, maxe - maxs); | ||
} | ||
|
||
int main(){ | ||
std::cout << "Input string: \n"; | ||
std::string str; | ||
std::cin >> str; | ||
|
||
std::cout << findLargestSubstr(str) << "\n"; | ||
|
||
return 0; | ||
} |