Last active
March 25, 2020 19:59
-
-
Save deeheem/776ab95a6f7aca5a641dac019f555f0a to your computer and use it in GitHub Desktop.
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
public int lengthOfLongestSubString(String s) { | |
int n = s.length(); | |
Set<Character> set = new HashSet<>(); | |
int ans = 0, i = 0, j = 0; | |
while (i < n && j < n) { | |
if (!set.contains(s.charAt(j))) { | |
set.add(s.charAt(j)); | |
j++; | |
ans = Math.max(ans, j - i); | |
} else { | |
set.remove(s.charAt(i)); | |
i++; | |
} | |
} | |
return ans; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment