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-> ...
随机推荐
- for语句
一.for语句的格式格式1:for (控制变量初始化表达式;条件表达式;增量表达式) 语句1; 格式2:for (控制变量初始化表达式;条件表达式;增量表达式){ 语句1; 语句2; -} 注意 ...
- (medium)LeetCode 278.First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the ...
- (整理)SQLServer 大数据的插入与查询
最近几天一直在折腾大数据量的查询,最后在索引.分页存储过程和控件以及视图的帮助下,搞定了.这篇文章记录解决问题时候查看的网友的分享链接,以及大数据量数据的插入链接. DatagridView Virt ...
- 执行powershell脚本
打开powershell运行窗口: powershell.exe C:\Users\Administrator\Desktop\a.ps1 -a $a. -a $a : vbs脚本路径(如 C:\h ...
- U盘分区之后如何恢复
操作步骤: 1.插入U盘. 2.按windows键,右键点击“运行”,再左键点击以管理员身份运行. 3.输入diskpart,按enter. 4.输入list disk,按enter. 5.之后会看到 ...
- Linux:远程到linux的图形界面
一般linux都没有安装图形界面,可以通过VNC服务来实现步骤如下: 一.安装vnc server1.查看是否安装vncrpm -q vnc-serverpackage vnc is not inst ...
- 深入理解JS异步编程二(分布式事件)
PubSub模式 从原生的js角度,我们要监听某事件的方法就是利用addEventListener方法,但是当我们的页面趋于复杂,比如要向某个元素添加多个处理事件,那么就要用一个封装函数汇集多个处理函 ...
- DHCP服务器的开始方式
方法一:采用DHCP服务器接口开启的方式 [Huawei]dhcp enable [Huawei]int g0/0/0[Huawei-GigabitEthernet0/0/0]ip add 192.1 ...
- {vlFeat}{Matlab}Linux中matlab的vlFeat配置
1.下载vlFeat编译后的版本binary package 2.解压后将 toolbox/,bin/,data/ 等文件夹复制到matlab新建工具箱目录 /toolbox/vlfeat/ 中 3. ...
- Apache错误:[error] (OS 10038)在一个非套接字上尝试了一个操作
Apache错误:[error] (OS 10038)在一个非套接字上尝试了一个操作 博客分类: vb2005xu软件学习 OSApache防火墙PHPWindows 日志如下:[ ...