There was an error while loading. Please reload this page.
1 parent 67bf347 commit dcde6e4Copy full SHA for dcde6e4
java/lengthOfLongestSubstring.java
@@ -1,3 +1,20 @@
1
+class Solution {
2
+ public int lengthOfLongestSubstring(String s) {
3
+ HashSet<Character> set = new HashSet<>();
4
+ int i=0, j=0, max=0;
5
+ while(j<s.length()){
6
+ if(set.contains(s.charAt(j)))
7
+ set.remove(s.charAt(i++));
8
+ else{
9
+ set.add(s.charAt(j++));
10
+ max = Math.max(max, set.size());
11
+ }
12
13
+ return max;
14
15
+}
16
+
17
18
public class Solution {
19
public int lengthOfLongestSubstring(String s) {
20
Queue<Character> queue = new LinkedList<>();
0 commit comments