
def swap(head):
dummy = ListNode(0)
dummy.next = head
prev, curr = dummy, head
while curr and curr.next:
## save prt
next_ptr = curr.next.next
second = curr.next
## reverse
second.next = curr
curr.next = next_ptr
prev.next = second
## update ptrs
prev = curr
curr = next_ptr
return dummy.next
'Algorithm > 기본 알고리즘' 카테고리의 다른 글
| leetcode 94. Binary Tree Inorder Traversal (0) | 2023.01.22 |
|---|---|
| leetcode 28. Find the index of the First Occurence in a String (0) | 2023.01.21 |
| boj-1931. 회의실배정 (0) | 2023.01.20 |
| boj-5397. 키 로거 (0) | 2023.01.20 |
| boj-7785. 회사에있는사람 (0) | 2023.01.20 |