[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-& ...
随机推荐
- WebStorm 8.0.1 注册码
username:24718-12042010 key:00001h6wzKLpfo3gmjJ8xoTPw5mQvY YA8vwka9tH!vibaUKS4FIDIkUfy!!f 3C"rQ ...
- 重拾OS的实现
好久没看OS实现了- -.感觉最近过的乱七八糟的.最为一名学渣,苟活于学霸之间实在是很辛苦啊.不过还是感觉要坚持下去比较好,决定每天学一点,写点感想.也算是通过这个平台逼迫一下自己.= =#. 今天回 ...
- ember - 观察者模式
Ember可以察觉所有属性的变化,包括计算属性.观察者是非常有用的,特别是计算属性绑定之后需要同步的时候. 观察者经常被Ember开发过度使用.Ember框架本身已经大量使用观察者,但是对于大多数的开 ...
- racle wm_concat(column)函数的使用
oracle wm_concat(column)函数使我们经常会使用到的,下面就教您如何使用oracle wm_concat(column)函数实现字段合并,如果您对oracle wm_concat( ...
- Jquery插件开发学习
一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#"),$("."),写了几年就对别人说非常熟悉JQuery.我曾经也是这样的人 ...
- TColor 与 RGB 的转换函数
function RGB2TColor(const R, G, B: Byte): Integer;begin // convert hexa-decimal values to RGB Resu ...
- POST 500 Internal Server Error
今天调试公司web后台时发现一个POST 500 Internal Server Error的错误. 本来VS本地调试没有发现这个问题,然后发布到服务器时才出现了.然后找了好久没找到什么原因,再仔细在 ...
- linux 项目环境搭建配置
经过三天加一上午的努力折腾,本地项目终于跑起来了,linux系统,重装后需要安装基本的php,nginx,mysql.php扩展需要安装curl ,memcache,memcached等.然后就是修改 ...
- NABCD
1) N (Need 需求) 随着科学技术的进步和计算机行业的迅速发展,人们的工作效率得到大大提高.计算机信息处理系统的引进已彻底改变了许多系统的经营管理. 图书管理系统是学校管理机制中的重要组成部分 ...
- PHP使用XHProf进行性能分析
1. 编译安装 wget http://pecl.php.net/get/xhprof-0.9.3.tgz tar zxvf xhprof-0.9.3.tgz cd xhprof-0.9.3/exte ...