# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None class Solution(object):
def swapPairs(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head == None or head.next == None:
return head
dummy=ListNode(0)
dummy.next=head
p=dummy
while p.next and p.next.next:
tmp=p.next.next
p.next.next=tmp.next
tmp.next=p.next
p.next=tmp
p=p.next.next
return dummy.next
相关文章
- [LeetCode]题解(python):025-Reverse Nodes in k-Group
- leetcode:Swap Nodes in Pairs
- Leetcode 线性表 Swap Nodes in Pairs
- [Leetcode][Python]25: Reverse Nodes in k-Group
- LeetCode OJ--Swap Nodes in Pairs
- 【LeetCode】863. All Nodes Distance K in Binary Tree 解题报告(Python)
- leetcode-algorithms-24 Swap Nodes in Pairs
- [LeetCode] Swap Nodes in Pairs 成对交换节点
- leetcode Swap Nodes in Pairs python
- Leetcode--Swap Nodes in Pairs