(self, head)
| 14 | |
| 15 | class Solution(object): |
| 16 | def swapPairs(self, head): |
| 17 | if head == None or head.next == None: |
| 18 | return head |
| 19 | cur = head |
| 20 | head = head.next |
| 21 | while cur and cur.next: |
| 22 | pNext = cur.next.next |
| 23 | cur.next.next = cur |
| 24 | if pNext: |
| 25 | if pNext.next: |
| 26 | cur.next = pNext.next |
| 27 | else: |
| 28 | cur.next = pNext |
| 29 | else: |
| 30 | cur.next = None |
| 31 | cur = pNext |
| 32 | return head |
| 33 | # recursion |
| 34 | def swapPairs2(self, head): |
| 35 | if not head or not head.next: |