Skip to content

Commit 28be855

Browse files
committed
Add Solution2.java to problems 0003
1 parent b046c8c commit 28be855

File tree

1 file changed

+13
-0
lines changed
  • solution/0003.Longest Substring Without Repeating Characters

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int lengthOfLongestSubstring(String s) {
3+
int i = 0, j = 0, length = s.length(), max = 0;
4+
Set<Character> set = new HashSet<>();
5+
while (i < length && j < length) {
6+
if (!set.contains(s.charAt(i))) {
7+
set.add(s.charAt(i++));
8+
max = Math.max(max, i - j);
9+
} else set.remove(s.charAt(j++));
10+
}
11+
return max;
12+
}
13+
}

0 commit comments

Comments
 (0)