leetcode Swap Nodes in Pairs python
# 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 Swap Nodes in Pairs python的更多相关文章
- LeetCode: Swap Nodes in Pairs 解题报告
Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For exam ...
- [LeetCode]Swap Nodes in Pairs题解
Swap Nodes in Pairs: Given a linked list, swap every two adjacent nodes and return its head. For exa ...
- [LeetCode] Swap Nodes in Pairs 成对交换节点
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
- leetcode—Swap Nodes in Pairs
1.题目描述 Given a linked list, swap every two adjacent nodes and return its head. For example, Given ...
- Leetcode:Swap Nodes in Pairs 单链表相邻两节点逆置
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- [LeetCode]Swap Nodes in Pairs 成对交换
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- [Leetcode] Swap nodes in pairs 成对交换结点
Given a linked list, swap every two adjacent nodes and return its head. For example,Given1->2-> ...
- LeetCode Swap Nodes in Pairs 交换结点对(单链表)
题意:给一个单链表,将其每两个结点交换,只改尾指针,不改元素值. 思路:迭代法和递归法都容易写,就写个递归的了. 4ms /** * Definition for singly-linked list ...
- 【LeetCode】Swap Nodes in Pairs 链表指针的应用
题目:swap nodes in pairs <span style="font-size:18px;">/** * LeetCode Swap Nodes in Pa ...
随机推荐
- 绿色mysql启动脚本
启动脚本如下:./mysqld_safe --defaults-file=/export/servers/mysql-5.5.38/my.cnf --ledir=/export/servers/mys ...
- c++数组操作
一.数组定义和初始化 : 一维数组初始化: : 标准方式一: ]; // value[i]的值不定,没有初始化 : 标准方式二: ] = {,}; // value[0]和value[1]的值分别为1 ...
- media queries(练习)
根据不同的窗口尺寸来选择使用不同的样式的示例 MAIN SUB 01 SUB 02
- javascript 获取元素宽高
style.width,clientWidth,offsetWidth <!doctype html> <html> <head> <meta charset ...
- SQL Server MYSQL 对外键建立索引的必要性
背景: 大家知道在定义外键时,都会给出on delete ..... on update .....: 这里指定的就是当主表的列发生变化时,从表的列要用怎么样的变化去迎合.对从表中的外键,建立索引 ...
- Linux05--Shell程序设计01
1.Shell脚本介绍 基本介绍: shell脚本是一个可执行的纯文本文件,由多个shell命令组成. 命令的执行是从上而下,从左而右的分析和执行 命令,参数间的多个空白也会被忽略 #是注释 #!用于 ...
- win7下设置 WiFi AP
开启windows 7的隐藏功能:虚拟WiFi和SoftAP(即虚拟无线AP),就可以让计算机变成无线路由器.实现共享上网. 1.以管理员身份运行命令提示符: “开始”---在搜索栏输入“cmd”-- ...
- Jdt Javax
http://www.javablogging.com/dynamic-in-memory-compilation/ http://www.java2s.com/Code/Java/JDK-6/Com ...
- unigui数据库连接池
UNIGUI for delphi,是一款WEB RIA开发框架.开发WEB程式如传统C/S般简单,众多DELPHIER趋之若鹜. 虽然上手非常容易,但要真正使用好,有些地方还是值得考究的. 网上有同 ...
- 第一章 andriod studio 安装与环境搭建
原文 http://blog.csdn.net/zhanghefu/article/details/9286123 第一章 andriod studio 安装与环境搭建 一.Android Stu ...