Skip to content

Commit f9b225a

Browse files
committed
[Medium] Title: 3. Longest Substring Without Repeating Characters - LeetCode
1 parent a4193a4 commit f9b225a

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int lengthOfLongestSubstring(String s) {
3+
Set<Character> seen = new HashSet<>();
4+
int length = 0; int start = 0;
5+
6+
for(int end = 0; end < s.length(); end++){
7+
// 중복 문자 확인
8+
while(seen.contains(s.charAt(end)) {
9+
seen.remove(s.charAt(start));
10+
start++;
11+
}
12+
13+
seen.add(s.charAt(end)); // 새로운 문자 추가
14+
length = Math.max(length, end - start + 1); // 길이 수정
15+
}
16+
17+
return length;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# [Midium] 3. Longest Substring Without Repeating Characters
2+
3+
[문제 링크](https://leetcode.com/problems/longest-substring-without-repeating-characters/)
4+
5+
### 문제 설명
6+
7+
Given a string s, find the length of the longest
8+
substring without repeating characters.
9+
10+
### 입출력
11+
Example 1:
12+
```
13+
Input: s = "abcabcbb"
14+
Output: 3
15+
```
16+
Explanation: The answer is "abc", with the length of 3.
17+
18+
Example 2:
19+
```
20+
Input: s = "bbbbb"
21+
Output: 1
22+
```
23+
Explanation: The answer is "b", with the length of 1.
24+
25+
Example 3:
26+
```
27+
Input: s = "pwwkew"
28+
Output: 3
29+
```
30+
Explanation: The answer is "wke", with the length of 3.
31+
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
32+
33+
### 제약조건
34+
- 0 <= s.length <= 5 * 104
35+
- s consists of English letters, digits, symbols and spaces.

0 commit comments

Comments
 (0)