Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/d4af031e8cb2b09bac740f0ccb18ad92 to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/d4af031e8cb2b09bac740f0ccb18ad92 to your computer and use it in GitHub Desktop.
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