[leetcode 24] Swap Nodes in k-Group
1 题目:
目前被墙,看不了。
2 思路:
比较简单,注意处理边界点就好
3 代码:
public ListNode swapPairs(ListNode head) {
int temp;
if(head == null){
return null;
}
ListNode h = head;
while(h != null){
ListNode node = h.next;
if(node!=null){
temp = h.val;
h.val = node.val;
node.val = temp;
h = h.next;
}
h = h.next;
}
return head;
}
注意处理奇数个的时候。
[leetcode 24] Swap Nodes in k-Group的更多相关文章
- 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] 24. Swap Nodes in Pairs 成对交换节点
Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...
- Java [leetcode 24]Swap Nodes in Pairs
题目描述: 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. For example, Given 1->2-& ...
- LeetCode 24. Swap Nodes in Pairs 成对交换节点 C++/Java
Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...
- (链表 递归) 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]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 24 Swap Nodes in Pairs (交换相邻节点)
题目链接: https://leetcode.com/problems/swap-nodes-in-pairs/?tab=Description Problem: 交换相邻的两个节点 如上 ...
- [LeetCode] 24. Swap Nodes in Pairs ☆
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
随机推荐
- Bug集
1. Spring MVC 双请求问题 viewresolver一定要放在servlet-dispatcher.xml里,否则会导致在请求成功后以后渲染页面,然后又发一次请求的状况,最后导致页面无法显 ...
- MD5编码的内存泄露
MD5CryptoServiceProvider 如果多次使用会产生内存溢出,如下这样调用几百万次就会出现内存 溢出. public static string MD5Encode(string so ...
- 大三CS狗一点想法
本文非技术文 十点半游戏的代码大概完成了1/3,想到今晚提早验收完汇编实验,还是副院长亲自验的,似乎很看好我的样子,然后问我的方向,导师和参加的项目.聊了几句后结束了对话,不禁又引发了我的一些思考. ...
- django 1.8 TEMPLE_DIR和STATICFILES_DIRS配置
django 1.6后settings.py文件中没有了TEMPLATE_DIRS模板目录和STATICFILES_DIRS静态访问目录,需要手动添加,最近也遇到这个问题,把解决办法说一下 1.环境 ...
- KVC
KVC可以修改私有的属性,估计也是底层 操作的.
- winxp计算机管理中服务详解
winxp计算机管理中服务详解01 http://blog.sina.com.cn/s/blog_60f923b50100efy9.html http://blog.sina.com.cn/s/blo ...
- Python多线程开发简介
Python的并发程序可以使用multiprocessing库.threading库.asyncio库.concurrent.futures库以及selectors库等等协助编写: multiproc ...
- 实战录 | Kafka-0.10 Consumer源码解析
<实战录>导语 前方高能!请注意本期攻城狮幽默细胞爆表,坐地铁的拉好把手,喝水的就建议暂时先别喝了:)本期分享人为云端卫士大数据工程师韩宝君,将带来Kafka-0.10 Consumer源 ...
- cookie session URL重写 与考试
状态管理.Cookie.Session.URL重写 HTTP协议:无状态的连接(每次连接都是新的请求)1.隐藏字段 <input type="hidden" name=&qu ...
- app开发遇到问题及解决
1:ios and Android 差异input type=text 当用户点击input框时,弹出手机键盘,ios会遮挡输入框 解决办法: pswOnFocus = function(){ tar ...