Skip to content

Commit 32f1ecc

Browse files
authored
Merge pull request #944 from mintheon/main
[mintheon] Week 7
2 parents 1bcf7e2 + 4dfafee commit 32f1ecc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

reverse-linked-list/mintheon.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* public class ListNode {
4+
* int val;
5+
* ListNode next;
6+
* ListNode() {}
7+
* ListNode(int val) { this.val = val; }
8+
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9+
* }
10+
*/
11+
// 실행시간: O(n)
12+
// 공간복잡도: O(1)
13+
class Solution {
14+
public ListNode reverseList(ListNode head) {
15+
ListNode prev = null;
16+
ListNode cur = head;
17+
18+
while(cur != null) {
19+
ListNode nextTemp = cur.next;
20+
cur.next = prev;
21+
prev = cur;
22+
cur = nextTemp;
23+
}
24+
25+
return prev;
26+
}
27+
}

0 commit comments

Comments
 (0)