24. Swap Nodes in Pairs leetcode Python 2016 new Season
来源:互联网 发布:淘宝上刻的公章能用吗 编辑:程序博客网 时间:2024/06/11 17:06
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4
, you should return the list as 2->1->4->3
.
Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.
Show Similar Problems
# 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 not head or not head.next: return head dummyHead = pNode = ListNode(None) pNode.next = head while pNode.next and pNode.next.next: tmp = pNode.next.next pNode.next.next = tmp.next tmp.next = pNode.next pNode.next = tmp pNode = pNode.next.next return dummyHead.next
0 0
- 24. Swap Nodes in Pairs leetcode Python 2016 new Season
- 24. Swap Nodes in Pairs Leetcode Python
- [leetcode: Python]24. Swap Nodes in Pairs
- 【LeetCode with Python】 Swap Nodes in Pairs
- Swap Nodes in Pairs Leetcode Python
- 【Leetcode】【python】Swap Nodes in Pairs
- python写算法题:leetcode: 24. Swap Nodes in Pairs
- LeetCode 24. Swap Nodes in Pairs (Python)
- [LeetCode]24.Swap Nodes in Pairs
- LeetCode --- 24. Swap Nodes in Pairs
- LeetCode 24.Swap Nodes in Pairs
- [Leetcode] 24. Swap Nodes in Pairs
- 【LeetCode】24.Swap Nodes in Pairs
- [leetcode] 24.Swap Nodes in Pairs
- **LeetCode 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs LeetCode
- leetcode 24. Swap Nodes in Pairs
- leetcode 24. Swap Nodes in Pairs
- 学习笔记 - Mac下隐藏文件的显示与隐藏
- 一种android安全机制-数字签名
- MySql获取随机行
- hdu 1226 超级密码
- CSS 弹性布局如何实现
- 24. Swap Nodes in Pairs leetcode Python 2016 new Season
- xcode C++一些简单设置
- Centos7原生的repo源下载---备忘
- orm2 中文文档 3.3 模型钩子
- fflush 函数
- 泛谈手机app测试
- 不同的OS
- [转]简明网络I/O模型---同步异步阻塞非阻塞之惑
- 从僵尸网络追踪到入侵检测 第4章 Honeyd动态模板防御扫描软件攻击