스터디 문제4번 LinkedList 정답률 52.5%
https://blog.naver.com/1ilsang/221597552829
class Solution {
public ListNode oddEvenList(ListNode head) {
ListNode odd = head;
if(odd == null) return head;
ListNode even = head.next;
if(even == null || even.next == null) return head;
go(head.next.next, odd, even, even, 3);
return odd;
}
private void go(ListNode head, ListNode odd, ListNode even, ListNode firstEven, int depth) {
if(head == null) {
even.next = null;
odd.next = firstEven;
return;
}
if(depth % 2 == 0) {
even.next = head;
even = even.next;
} else {
odd.next = head;
odd = odd.next;
}
go(head.next, odd, even, firstEven, depth + 1);
}
}
'Leetcode' 카테고리의 다른 글
Leetcode <Binary Search> 704. Binary Search 50.8% Easy (0) | 2020.04.10 |
---|---|
Leetcode <Sort> 242. Valid Anagram 백준 6996번 애너그램 (0) | 2020.04.05 |
Leetcode 621. Task Scheduler 47.7% Medium (0) | 2020.04.03 |
Leetcode <Heap> 264. Ugly Number II 38.9% Medium (0) | 2020.04.03 |
Leetcode 96. Unique Binary Search Trees 50.1% Medium (0) | 2020.04.03 |
댓글