Skip to content

Instantly share code, notes, and snippets.

@mashimom
Created September 23, 2020 15:39
Show Gist options
  • Save mashimom/08a0f3d7e61a47dbe7a2d886b4659eb0 to your computer and use it in GitHub Desktop.
Save mashimom/08a0f3d7e61a47dbe7a2d886b4659eb0 to your computer and use it in GitHub Desktop.
faster - longest substring without repeating characters
class Solution {
public int lengthOfLongestSubstring(String s) {
int r = 0;
Set<Character> set;
for(int i=0;i<s.length();i++) {
set = new HashSet<>();
int t = 0;
for(int j=i;j<s.length();j++){
if(set.contains(s.charAt(j))) break;
set.add(s.charAt(j));
// System.out.println(s.substring(i,j+1));
// System.out.println(set);
if(set.size() > r) r=set.size();
}
}
return r;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment