Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 28be855

Browse files
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
Lines changed: 13 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /