Skip to content

Commit e7ee6c5

Browse files
committed
Time: 14 ms (43.54%), Space: 46.6 MB (20.81%) - LeetHub
1 parent 78202ca commit e7ee6c5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int lengthOfLongestSubstring(String s) {
3+
char [] arr = s.toCharArray();
4+
Set charSet = new HashSet<Character>();
5+
int l = 0;
6+
int res = 0;
7+
for(int i=0; i < arr.length; i++){
8+
while(charSet.contains(arr[i])){
9+
charSet.remove(arr[l]);
10+
l += 1;
11+
12+
}
13+
charSet.add(arr[i]);
14+
res = Math.max(res,i - l + 1);
15+
}
16+
return res;
17+
18+
}
19+
}

0 commit comments

Comments
 (0)