Skip to content

Commit 9a4fe5e

Browse files
author
Jinbeom
committed
Refactor Reverse Linked List
1 parent da4df4f commit 9a4fe5e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

reverse-linked-list/kayden.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
// 공간복잡도: O(1)
1313
class Solution {
1414
public ListNode reverseList(ListNode head) {
15-
1615
ListNode prev = null;
1716

1817
while (head != null){
19-
ListNode curr = new ListNode(head.val, prev);
20-
prev = curr;
21-
head = head.next;
18+
ListNode next = head.next;
19+
head.next = prev;
20+
prev = head;
21+
head = next;
2222
}
2323

2424
return prev;

0 commit comments

Comments
 (0)