File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * ๋ฌธ์ ์ค๋ช
3
+ * - ๋งํฌ๋ ๋ฆฌ์คํธ๋ฅผ ๋ค์ง๋ ๋ฌธ์
4
+ *
5
+ * ์์ด๋์ด
6
+ * - ๋
ธ๋๋ฅผ ์ํํ๋ฉด์ ๋ค์ ๋
ธ๋๋ฅผ ๋ฏธ๋ฆฌ ๊ธฐ์ตํด๋๊ณ , ํ์ดํ๋ฅผ ๋ฐ๋๋ก ๋๋ฆฐ ํ ํ์นธ์ฉ ์ด๋ํ๋ค.
7
+ * - prev, head(current) ๋ ๊ฐ์ง ํฌ์ธํฐ๊ฐ ํ์
8
+ */
9
+
10
+ /**
11
+ * Definition for singly-linked list.
12
+ * class ListNode {
13
+ * val: number
14
+ * next: ListNode | null
15
+ * constructor(val?: number, next?: ListNode | null) {
16
+ * this.val = (val===undefined ? 0 : val)
17
+ * this.next = (next===undefined ? null : next)
18
+ * }
19
+ * }
20
+ */
21
+
22
+ interface ListNode {
23
+ val : number ;
24
+ next : ListNode | null ;
25
+ }
26
+
27
+ function reverseList ( head : ListNode | null ) : ListNode | null {
28
+ let prev : ListNode | null = null ;
29
+
30
+ while ( head ) {
31
+ const next = head . next ;
32
+ head . next = prev ;
33
+ prev = head ;
34
+ head = next ;
35
+ }
36
+
37
+ return prev ;
38
+ }
You canโt perform that action at this time.
0 commit comments