def swapPairs(self, head): """ :type head: ListNode :rtype: ListNode """ first, second = head, head while first and first.next: second = second.next first.val, second.val = second.val, first.val first = second.next second = first return head
Clever, but you're not actually swapping the nodes here. That being said, they didn't say you couldn't just swap the values.
@mjeffe6 You'r right. I didn't notice that. My answer is not standard enough... Thanks for reminding me. :)