- #1
member 428835
Hi all, I'm trying to write a small script to count the largest number of non-repeating strings in a vector. Below is what I wrote, but insert, erase, and find aren't working. Any ideas why?
If the script isn't correct, you don't have to correct it. I'm just wondering why those three commands don't work.
If the script isn't correct, you don't have to correct it. I'm just wondering why those three commands don't work.
C++:
#include <iostream>
#include <unordered_set>
int long_sub(std::string s) {
int count = 0, L = 0;
std::unordered_set<std::string> used_str;
int max_count = 0;
for(int R = 0; R < s.length(); R++) {
if(used_str.find(s[R]) != used_str.end()) { // IF s[R] IS IN used_str
used_str.erase(s[L]);
L += 1;
count -= 1;
} else { // IF s[R] IS NOT IN used_str
used_str.insert(s[R]);
R += 1;
count += 1;
}
max_count = std::max(max_count, count);
return count;
}
}
int main()
{
std::string s = "abcabcbb";
auto sol = long_sub(s);
std::cout << sol;
}