leetcode之Swap Nodes in Pairs
来源:互联网 发布:php大数据处理 编辑:程序博客网 时间:2024/06/14 00:43
这题要求是常数空间,不能修改值,只能修改node,所以直接在node上进行操作。代码如下:
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def swapPairs(self, head): """ :type head: ListNode :rtype: ListNode """ if head: if head.next: b = head.next head.next = head.next.next b.next = head head = b print head.val left = head.next while left.next and left.next.next: b = left.next left.next = b.next c = left.next.next left.next.next = b b.next = c left = left.next.next return head
0 0
- leetcode之Swap Nodes in Pairs
- LeetCode 之 Swap Nodes in Pairs
- LeetCode之Swap Nodes in Pairs
- LeetCode之Swap Nodes in Pairs
- LeetCode之Swap Nodes in Pairs
- 【LeetCode】之Swap Nodes in Pairs
- 【Leetcode】之Swap Nodes in Pairs
- leetcode之Swap Nodes in Pairs
- leetcode之Swap Nodes in Pairs
- LeetCode之24----Swap Nodes in Pairs
- Leetcode 之 Swap Nodes in Pairs
- LeetCode:Swap Nodes in Pairs
- LeetCode: Swap Nodes in Pairs
- [Leetcode] Swap Nodes in Pairs
- LeetCode : Swap Nodes in Pairs
- [LeetCode] Swap Nodes in Pairs
- Leetcode: Swap nodes in pairs
- [LeetCode]Swap Nodes in Pairs
- android JNI开发准备
- ViewPager 的切换动画效果
- 颜色(三):CIColor
- NEHE阅读笔记-2D多边形
- Git使用教程详解之一 Git起步
- leetcode之Swap Nodes in Pairs
- iOS NSTimer详解
- Ubuntu15.10 apache2 使用HTTPS
- Linux下串口设备的使用
- 能否改变UIDatePicker的大小?怎么改变
- <LeetCode OJ> 2. Add Two Numbers
- Android 使用APICloude 数据库的方法
- hdu 2566 统计硬币 数学解法
- WAMP 修改默认根目录www