LeetCode OJ--Swap Nodes in Pairs
https://oj.leetcode.com/problems/swap-nodes-in-pairs/
链表的处理
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *swapPairs(ListNode *head) {
ListNode *dummy = new ListNode(-);
if(head == NULL)
return dummy->next; dummy->next = head; ListNode *tail = dummy; ListNode *current = head;
ListNode *second = head->next;
while(current && second)
{
tail->next = second;
current->next = second->next;
second->next = current; current = current->next;
if(current == NULL)
break;
second = current->next;
tail = tail->next;
tail = tail->next; }
return dummy->next;
}
};
LeetCode OJ--Swap Nodes in Pairs的更多相关文章
- 【LeetCode】Swap Nodes in Pairs 链表指针的应用
题目:swap nodes in pairs <span style="font-size:18px;">/** * LeetCode Swap Nodes in Pa ...
- 【LeetCode】Swap Nodes in Pairs 解题报告
Swap Nodes in Pairs [LeetCode] https://leetcode.com/problems/swap-nodes-in-pairs/ Total Accepted: 95 ...
- 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 ...
- [LeetCode] 24. Swap Nodes in Pairs ☆☆☆(链表,相邻两节点交换)
Swap Nodes in Pairs 描述 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表. 示例: 给定 1->2->3->4, 你应该返回 2->1->4 ...
- LeetCode 024 Swap Nodes in Pairs
题目描述:Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...
- leetcode 【 Swap Nodes in Pairs 】python 实现
题目: Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1-> ...
- [LeetCode] 24. Swap Nodes in Pairs 成对交换节点
Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...
- 【leetcode】Swap Nodes in Pairs (middle)
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
- Java for LeetCode 024 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-> ...
随机推荐
- 24. Longest Consecutive Sequence
Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...
- 使用CSS和jQuery实现tab页
使用jquery来操作DOM是极大的方便和简单,这儿只是简单的用一个使用css和jquery来实现的tab页来简单介绍一些jQuery的一些方便使用的方法,下面是html文件: <!DOCTYP ...
- sql 2008 R2添加对MySql的远程服务器链接
(1).我的sql 2008 R2所在的系统为Windows server 2008 *64 (2).MySQL所在的系统为Windows server 2003 *86 我想要实现的是在sql 20 ...
- js编译器的一些简单原理
有没有发现在写代码的时候,往往会遇到一些莫名其妙的错误,然后时间紧急不得不去网上查阅一些代码.虽然要实现的功能解决了,但是看被拷贝的代码好多真心看不懂,以后遇到诸如此类的问题,如果查阅不到这些代码的话 ...
- 【转】用C#调用Windows API向指定窗口发送
一.调用Windows API. C#下调用Windows API方法如下: 1.引入命名空间:using System.Runtime.InteropServices; 2.引用需要使用的方法,格式 ...
- php判断 !==false
测试 if($res !== false){ echo "未定义通过<br>"; }else{ echo "未定义不通过<br>"; } ...
- apache-jmeter学习文档
http://www.cnblogs.com/TankXiao/p/4045439.html#sampler
- Bitmap 的bitmapdata和texture区别
Texture:纹理类是对不同平台不同的图片资源的封装在HTML5中,资源是一个HTMLElement对象在OpenGL / WebGL中,资源是一个提交GPU后获取的纹理idTexture类封装了这 ...
- MySQL 5.7 深度解析: 半同步复制技术
复制架构衍生史 在谈这个特性之前,我们先来看看MySQL的复制架构衍生史. MySQL的复制分为四种: 普通的replication,异步同步. 搭建简单,使用非常广泛,从mysql诞生之初,就产生了 ...
- js判断是否安装pdf播放器
function isPDFPluginInstall() { if (!isIE()) { //ie 浏览器 和 非ie浏览器支持 // not ie if (navigator.plugins & ...