Skip to content

Commit 92671d0

Browse files
committed
reverse linked list
1 parent 5b25a99 commit 92671d0

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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/reverse-linked-list/description/
7+
- 문제 이름 : reverse-linked-list
8+
- 문제 번호 : 206
9+
- λ‚œμ΄λ„ : easy
10+
- μΉ΄ν…Œκ³ λ¦¬ :
11+
12+
# 아이디어
13+
- μ–΄λ–€ λ°©λ²•μœΌλ‘œ μ ‘κ·Όν–ˆλŠ”μ§€ μ„œμˆ 
14+
- 포슀 vs μ΅œμ ν™” 아이디어 차이 λ“±
15+
- μž‘λ„μ— λŒ€ν•œ κ³ λ €
16+
17+
# βœ… μ½”λ“œ (Solution)
18+
19+
```cpp
20+
/**
21+
* Definition for singly-linked list.
22+
* struct ListNode {
23+
* int val;
24+
* ListNode *next;
25+
* ListNode() : val(0), next(nullptr) {}
26+
* ListNode(int x) : val(x), next(nullptr) {}
27+
* ListNode(int x, ListNode *next) : val(x), next(next) {}
28+
* };
29+
*/
30+
class Solution {
31+
public:
32+
ListNode* reverseListSubFunc(ListNode* before, ListNode* after){
33+
if(!after){
34+
return before;
35+
}
36+
37+
auto next = after->next;
38+
after->next = before;
39+
return reverseListSubFunc(after, next);
40+
}
41+
42+
ListNode* reverseList(ListNode* head) {
43+
return reverseListSubFunc(nullptr, head);
44+
}
45+
};
46+
```
47+
48+
49+
# πŸ” μ½”λ“œ μ„€λͺ…
50+
51+
52+
# μ΅œμ ν™” 포인트 (Optimality Discussion)
53+
β€’ μ΅œμ ν™”ν•œ μ΄μœ μ™€ 원리
54+
β€’ 더 쀄일 수 μžˆλŠ” μ—¬μ§€λŠ” μžˆλŠ”κ°€?
55+
β€’ κΈ°μ‘΄ 방법 λŒ€λΉ„ μ–Όλ§ˆλ‚˜ νš¨μœ¨μ μ΄μ—ˆλŠ”μ§€
56+
57+
# πŸ§ͺ ν…ŒμŠ€νŠΈ & μ—£μ§€ μΌ€μ΄μŠ€
58+
59+
# πŸ“š κ΄€λ ¨ 지식 볡슡
60+
61+
# πŸ” 회고
62+
63+

0 commit comments

Comments
Β (0)