Skip to content

Commit dcde6e4

Browse files
committed
0711
1 parent 67bf347 commit dcde6e4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

java/lengthOfLongestSubstring.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
118
public class Solution {
219
public int lengthOfLongestSubstring(String s) {
320
Queue<Character> queue = new LinkedList<>();

0 commit comments

Comments
 (0)