# 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的更多相关文章

  1. LeetCode: Swap Nodes in Pairs 解题报告

    Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For exam ...

  2. [LeetCode]Swap Nodes in Pairs题解

    Swap Nodes in Pairs: Given a linked list, swap every two adjacent nodes and return its head. For exa ...

  3. [LeetCode] Swap Nodes in Pairs 成对交换节点

    Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...

  4. leetcode—Swap Nodes in Pairs

    1.题目描述 Given a linked list, swap every two adjacent nodes and return its head.   For example, Given ...

  5. Leetcode:Swap Nodes in Pairs 单链表相邻两节点逆置

    Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...

  6. [LeetCode]Swap Nodes in Pairs 成对交换

    Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...

  7. [Leetcode] Swap nodes in pairs 成对交换结点

    Given a linked list, swap every two adjacent nodes and return its head. For example,Given1->2-> ...

  8. LeetCode Swap Nodes in Pairs 交换结点对(单链表)

    题意:给一个单链表,将其每两个结点交换,只改尾指针,不改元素值. 思路:迭代法和递归法都容易写,就写个递归的了. 4ms /** * Definition for singly-linked list ...

  9. 【LeetCode】Swap Nodes in Pairs 链表指针的应用

    题目:swap nodes in pairs <span style="font-size:18px;">/** * LeetCode Swap Nodes in Pa ...

随机推荐

  1. [week1]每周总结与工作计划

    实在不想说这句俗话,因为实在太俗了.但是俗话说,“吾日三省吾身”,我虽然难以做到每天反省那么多次,但是每周来一次就很不错了.于是我决定: 从这周开始准备每周都写每周总结与工作计划. 很好,就这样说定了 ...

  2. Java File类读取文件属性

     package myjavademo;import java.io.*; publicclass MyJavaDemo {     public static void main(String[]  ...

  3. javascript——touch事件介绍与实例演示

      分类: javascript2014-02-12 16:42 1742人阅读 评论(0) 收藏 举报 touch事件touchmovetouchstarttouchend 前言 诸如智能手机和平板 ...

  4. Http权威指南笔记(二) Http状态码大全

    100~199—信息状态码 200~299—成功状态码 客户端发请求时,这些请求通常都是成功的. 300~399—重定向状态码 重定向状态码告知客户端使用代替位置来访问他们所感兴趣的资源. 400~4 ...

  5. Asp.net MVC + EF6.0 经常出现的问题

    1.运行视图时出现问题:未能加载文件或程序集"EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c ...

  6. Oracle触发器Trigger2行级

    create table trigger_t2( id int, name ), age int ); /* --创建一个before update的触发器-控制每一行,行级 --只有行级的才会有:n ...

  7. iOS设计模式解析(二)抽象工厂方法

    抽象工厂方法:提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类 与工厂方法区别: 抽象工厂通过对象组合创建抽象产品.工厂通过类集成创建抽象产品 抽象工厂创建多系列产品.工厂创建一种产 ...

  8. <转>Java的一些历史

      Java是一种固执己见的语言,它具有很好的可读性,初级程序员很容易上手,具有长期稳定性和可支持性.但这些设计决定也付出了一定的代价:冗长的代码,类型系统与其它语言相比显得缺乏弹性. 然而,Java ...

  9. Collections类方法详解

    Collections则是集合类的一个工具类/帮助类,其中提供了一系列静态方法,用于对集合中元素进行排序.搜索以及线程安全等各种操作. 1) 排序(Sort)使用sort方法可以根据元素的自然顺序 对 ...

  10. 多个DLL合并,DLL合并到EXE

    1:) 下载 http://download.microsoft.com/download/1/3/4/1347C99E-9DFB-4252-8F6D-A3129A069F79/ILMerge.msi ...