Skip to content

Commit f3f44e4

Browse files
committed
reorder list
1 parent 6efb604 commit f3f44e4

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

reorder-list/se6816.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
class Solution {
3+
public void reorderList(ListNode head) {
4+
if(head.next == null) return;
5+
6+
ListNode prev = null;
7+
while (true) {
8+
ListNode tail = head;
9+
while (tail.next != null) {
10+
prev = tail;
11+
tail = tail.next;
12+
}
13+
14+
if (prev == head) break;
15+
16+
// tail 이동
17+
ListNode headNext = head.next;
18+
prev.next = null;
19+
head.next = tail;
20+
tail.next = headNext;
21+
22+
head = headNext;
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)