Skip to content

Commit 8d93ae0

Browse files
committed
reverse linked Longest Substring Without Repeating Characters
1 parent 92671d0 commit 8d93ae0

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# μ—°κ΄€ 링크
2+
- [문제 풀이 μŠ€μΌ€μ€„](https://github.com/orgs/DaleStudy/projects/6/views/5)
3+
- [λ‹΅μ•ˆ μ½”λ“œ μ œμΆœλ²•](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C)
4+
5+
# Problem
6+
- 문제 링크 : https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
7+
- 문제 이름 : Longest Substring Without Repeating Characters
8+
- 문제 번호 :3
9+
- λ‚œμ΄λ„ : medium
10+
- μΉ΄ν…Œκ³ λ¦¬ :
11+
12+
# 아이디어
13+
- λ§ˆμ§€λ§‰ μœ„μΉ˜μ— λŒ€ν•œ μ €μž₯을 ν†΅ν•œ λΉ λ₯Έ 탐색
14+
15+
# βœ… μ½”λ“œ (Solution)
16+
17+
```cpp
18+
class Solution {
19+
public:
20+
int lengthOfLongestSubstring(string s) {
21+
unordered_map<char, int> latestIdx;
22+
int maxLength = 0;
23+
int start = 0;
24+
for(int idx = 0; idx<s.size();idx++){
25+
char curC = s[idx];
26+
if(latestIdx.find(curC) != latestIdx.end() && latestIdx[curC] >= start){
27+
start = latestIdx[curC]+1;
28+
}
29+
latestIdx[curC] = idx;
30+
maxLength = max(maxLength, idx-start+1);
31+
}
32+
return maxLength;
33+
34+
}
35+
};
36+
37+
```
38+
39+
# πŸ” μ½”λ“œ μ„€λͺ…
40+
41+
42+
# μ΅œμ ν™” 포인트 (Optimality Discussion)
43+
β€’ μ΅œμ ν™”ν•œ μ΄μœ μ™€ 원리
44+
β€’ 더 쀄일 수 μžˆλŠ” μ—¬μ§€λŠ” μžˆλŠ”κ°€?
45+
β€’ κΈ°μ‘΄ 방법 λŒ€λΉ„ μ–Όλ§ˆλ‚˜ νš¨μœ¨μ μ΄μ—ˆλŠ”μ§€
46+
47+
# πŸ§ͺ ν…ŒμŠ€νŠΈ & μ—£μ§€ μΌ€μ΄μŠ€
48+
49+
# πŸ“š κ΄€λ ¨ 지식 볡슡
50+
51+
# πŸ” 회고
52+
53+

0 commit comments

Comments
Β (0)