【leetcode❤python】24. Swap Nodes in Pairs
#-*- coding: UTF-8 -*-
# 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
"""
dummy=ListNode(0)
dummy.next=head
pre,cur=dummy,head
while cur and cur.next: #cur=1,cur.next=2
pre.next=cur.next #dummy--->2
cur.next=cur.next.next #1-->3
pre.next.next=cur #2-->1
pre,cur=cur,cur.next #pre=1,cur=3
return dummy.next
【leetcode❤python】24. Swap Nodes in Pairs的更多相关文章
- 【LeetCode】24. Swap Nodes in Pairs (3 solutions)
Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For exam ...
- 【一天一道LeetCode】#24. Swap Nodes in Pairs
一天一道LeetCode系列 (一)题目 Given a linked list, swap every two adjacent nodes and return its head. For exa ...
- 【LeetCode】24. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
- leetcode个人题解——#24 Swap Nodes in Pairs
因为不太熟悉链表操作,所以解决方法烦了点,空间时间多有冗余. 代码中l,r分别是每一组的需要交换的左右指针,temp是下一组的头指针,用于交换后链接:res是交换后的l指针,用于本组交换后尾指针在下一 ...
- [Leetcode][Python]24: Swap Nodes in Pairs
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 24: Swap Nodes in Pairshttps://oj.leetc ...
- 24. Swap Nodes in Pairs
24. Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...
- 24. Swap Nodes in Pairs(M);25. Reverse Nodes in k-Group(H)
24. Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...
- Leetcode 题目整理-6 Swap Nodes in Pairs & Remove Duplicates from Sorted Array
24. Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...
- leetCode 24. Swap Nodes in Pairs (双数交换节点) 解题思路和方法
Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For exa ...
随机推荐
- js 获取select 中option 的个数
//document.writeln(document.getElementById("sel").options.length); //document.writeln(docu ...
- 夺命雷公狗ThinkPHP项目之----企业网站10之栏目的编辑完善(无限极分类的完成)
我们编辑首先就要考虑将下拉框效果实现出来,然后再进行下一步操作: 我们用到了Model层的操作,在第8讲里面其实已经写好了catTree方法,控制器如下所示: 然后在列表页然他变量进行输出 然后开始通 ...
- lower power设计中的DVFS设计
Pswitch = Ceff * Vvdd^2*Fclk, Pshort-circuit = Isc * Vdd * Fclk, Pleakage = f(Vdd, Vth, W/L) 尽管对电压的s ...
- switch结构2016/03/08
Switch 03/08 一.结构 switch(){ case *: ;break;……default: ;brek;} 练习:输入一个日期,判断这一年第几天? Console.Write(&q ...
- 通过restore database时重命名数据库rename database
backup database testdb to disk='c:\testdb_ful.bak' with compression backup log testdb to disk='c:\te ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON AffineTransRegion
zw版[转发·台湾nvp系列Delphi例程]HALCON AffineTransRegion unit Unit1;interfaceuses Windows, Messages, SysUtils ...
- Cannot spawn... TortoisePlink
error: cannot spawn "C:\Program Files\TortoiseGit\bin\TortoisePlink.exe": No such file or ...
- 什么是商业智能BI和实施BI的解决方案【转】
商业智能,或BI,是一种统称,泛指用于对一个企业的原始数据进行分析的各种各样的软件系统.商业智能(BI)是由若干相关的活动组成的领域,包括数据挖掘,在线分析处理,查询和报表. 企业用商业智能(BI)来 ...
- UIView的ContentMode
UIViewContentMode typedef enum { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectF ...
- Mac Book 上安装Windows 8 / 10 以后安装 Hyper-v 无法正常使用问题---虚拟化已禁止问题
Mac book由于工作需要装了双启动,平时工作用 Windows 10, 由于有些老程序无法启动,还得再装一个虚拟机. 起初装 WMWare 开始装 7.1版本,结果没安装完就直接崩溃重启, 网上反 ...