File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 13
13
| :----:| -----------------------------------------------------------------------------------------------------------------------------------------------------------| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| :---------------------------------------------------------------------------------------------------------------------------------:|
14
14
| 1 | [ Two Sum] ( https://leetcode.com/problems/two-sum/ ) | [ ![ Java] ( assets/java.png )] ( src/TwoSum.java ) [ ![ Python] ( assets/python.png )] ( python/two_sum.py ) | [ ![ java-yt] ( assets/java-yt.png )] ( https://youtu.be/9wSL_7NN-A8 ) [ ![ python-yt] ( assets/python-yt.png )] ( https://youtu.be/N5FXCTg0TDE ) |
15
15
| 2 | [ Add Two Numbers] ( https://leetcode.com/problems/add-two-numbers ) | [ ![ Java] ( assets/java.png )] ( src/AddTwoNumbers.java ) | |
16
+ | 3 | [ Longest Substring Without Repeating Characters] ( https://leetcode.com/problems/longest-substring-without-repeating-characters ) | [ ![ Java] ( assets/java.png )] ( src/LongestSubstringWithoutRepeatingCharacters.java ) | |
16
17
| 7 | [ Reverse Integer] ( https://leetcode.com/problems/reverse-integer/ ) | [ ![ Java] ( assets/java.png )] ( src/ReverseInteger.java ) [ ![ Python] ( assets/python.png )] ( python/reverse_integer.py ) | [ ![ java-yt] ( assets/java-yt.png )] ( https://youtu.be/7bOhyl5lWjI ) [ ![ python-yt] ( assets/python-yt.png )] ( https://youtu.be/lmLG30TLcSg ) |
17
18
| 9 | [ PalindromeNumber] ( https://leetcode.com/problems/palindrome-number/ ) | [ ![ Java] ( assets/java.png )] ( src/PalindromeNumber.java ) [ ![ Python] ( assets/python.png )] ( python/palindrome_number.py ) | |
18
19
| 13 | [ Roman To Integer] ( https://leetcode.com/problems/roman-to-integer/ ) | [ ![ Java] ( assets/java.png )] ( src/RomanToInteger.java ) [ ![ Python] ( assets/python.png )] ( python/roman_to_integer.py ) | [ ![ java-yt] ( assets/java-yt.png )] ( https://youtu.be/BCue_mO_81A ) [ ![ python-yt] ( assets/python-yt.png )] ( https://youtu.be/8h_yGTNvKMA ) |
Original file line number Diff line number Diff line change
1
+ // https://leetcode.com/problems/longest-substring-without-repeating-characters
2
+ // T: O(|s|)
3
+ // S: O(1)
4
+
5
+ import java .util .HashSet ;
6
+ import java .util .Set ;
7
+
8
+ public class LongestSubstringWithoutRepeatingCharacters {
9
+ public int lengthOfLongestSubstring (String s ) {
10
+ final Set <Character > letters = new HashSet <>();
11
+ int maxLength = 1 ;
12
+ for (int i = 0 , j = 0 ; i < s .length () ; i ++) {
13
+ if (letters .contains (s .charAt (i ))) {
14
+ while (letters .contains (s .charAt (i ))) {
15
+ letters .remove (s .charAt (j ++));
16
+ }
17
+ }
18
+ letters .add (s .charAt (i ));
19
+ maxLength = Math .max (maxLength , i - j + 1 );
20
+ }
21
+ return maxLength ;
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments