Created
September 23, 2020 15:39
-
-
Save mashimom/08a0f3d7e61a47dbe7a2d886b4659eb0 to your computer and use it in GitHub Desktop.
faster - longest substring without repeating characters
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
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