leetcode 024
Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.
Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.
head
dimmy -> 1 --> 2 --> 3 --> 4 对cur先后再前
pre cur
class Solution {
public:
ListNode* swapPairs(ListNode* head) {
if(head == NULL)
return head;
ListNode *dummy = new ListNode(0);
dummy->next = head;
ListNode *pre = dummy, *cur=head;
while(cur&&cur->next)
{
pre->next = cur->next;
cur->next = cur->next->next;
pre->next->next = cur;
pre = cur;
cur = cur->next;
}
return dummy->next;
}
};
leetcode 024的更多相关文章
- 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 024 Swap Nodes in Pairs 交换链表中相邻的两个节点
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2-> ...
- 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】024. Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
- LeetCode Animation 题目图解汇总(持续更新中...)
我会尽力将LeetCode上所有的题目都用动画的形式演示出来,期待与你见证这一天! GitHub Repo:LeetCode Animation Follow: MisterBooo · GitHub ...
- 我为什么要写LeetCode的博客?
# 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
随机推荐
- 领域驱动设计(DDD)
领域驱动设计(DDD)实现之路 2004年,当Eric Evans的那本<领域驱动设计——软件核心复杂性应对之道>(后文简称<领域驱动设计>)出版时,我还在念高中,接触到领域驱 ...
- attr与prop的区别
我们在获取checked属性值的时候,如果被选中则值为"checked"没选中获取值就是undefined. (引述他人)因为在有些浏览器中比如说只要写disabled,check ...
- ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork 制作一个添加新闻功能
本文将交大伙怎么集成ASP.NET MVC + 百度富文本编辑器 + EasyUi + EntityFrameWork来制作一个新闻系统 先上截图: 添加页面如下: 下面来看代码部分 列表页如下: @ ...
- WPF界面按钮美化
在App.xaml里加入全局按钮样式 <Application x:Class="WpfButton.App" xmlns="http://schemas.micr ...
- asp.net 的一个简单进度条功能
我们先看下效果 我点击了按钮后他会显示进度页面,进度完成后,进度条消失,其实也是比较简单的了. 我们需要一个进度条代码文件ProgressBar.htm(注意:是没有head这些标签的) <sc ...
- oracle数据库对date字段类型存在空值进行排序的处理方法
oracle数据库对date字段类型存在空值进行排序的处理方法 oracle 数据库,如果表中有一个字段类型为date,且该字段类型存在空值,并且需要排序, 解决方法为使用oracl ...
- Asp.net mvc 大文件上传 断点续传
Asp.net mvc 大文件上传 断点续传 进度条 概述 项目中需要一个上传200M-500M的文件大小的功能,需要断点续传.上传性能稳定.突破asp.net上传限制.一开始看到51CTO上的这 ...
- iOS AVCaptureDevice的一些动西
http://blog.sina.com.cn/s/blog_78a55c9f01011apc.html
- 开源来自百度商业前端数据可视化团队的超漂亮动态图表--ECharts
开源来自百度商业前端数据可视化团队的超漂亮动态图表--ECharts 本人项目中最近有需要图表的地方,偶然发现一款超级漂亮的动态图标js图表控件,分享给大家,觉得好用的就看一下.更多更漂亮的演示大家可 ...
- 浅谈一下SSI+Oracle框架的整合搭建
浅谈一下SSI+Oracle框架的整合搭建 最近换了一家公司,公司几乎所有的项目都采用的是Struts2+Spring+Ibatis+Oracle的架构,上一个东家一般用的就是JSF+Spring,所 ...