Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Longest_Sub_string_without_Repeat_Characters_BruteForce
class Solution {
public:
bool isAllUnique(string &s, int start, int end)
{
unordered_set<char> hash;
for(int i = start; i <= end; i++)
{
if(hash.find(s[i]) != hash.end())
return false;
hash.insert(s[i]);
}
return true;
}
int lengthOfLongestSubstring(string s) {
int len = s.size();
int maxLen = s.empty()? 0 : 1;
for(int i = 0; i < len; i++)
{
for(int j = i + 1; j< len; j++)
{
if(isAllUnique(s, i, j))
maxLen = max(j - i + 1, maxLen);
}
}
return maxLen;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment