Skip to content

Commit

Permalink
Time: 7 ms (47.56%) | Memory: 44.4 MB (69.30%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhieu-it committed Feb 21, 2024
1 parent f13a37c commit b9eba4e
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public int lengthOfLongestSubstring(String s) {
Set<Character> ss = new HashSet<>();
int i = 0, ans = 0;
for (int j = 0; j < s.length(); ++j) {
char c = s.charAt(j);
while (ss.contains(c)) {
ss.remove(s.charAt(i++));
}
ss.add(c);
ans = Math.max(ans, j - i + 1);
}
return ans;
}
}

0 comments on commit b9eba4e

Please sign in to comment.