您的位置:首页 > Web前端 > Node.js

LeetCode-24-Swap-Nodes-in-Pairs 链表递归水题

2017-09-11 14:06 399 查看
# 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:return None
if head.next==None:return head
nextHead=self.swapPairs(head.next.next)
h=head.next
h.next=head
h.next.next=nextHead
return h
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: