[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-& ...
随机推荐
- jQuery Ajax传递数组到asp.net web api参数为空
前端: var files = []; files.push({ FileName: "1.jgp", Extension: ".jgp", FileType: ...
- 约瑟夫环问题(c++)
#include <iostream> struct node{ int payload; node* next; node(int payload){this->payload = ...
- js实例:验证只能输入数字和一个小数点
分享一个javascript脚本代码,用于验证只能输入数字和一个小数点,检测数字输入是否符合要求,效果不错,有用到的朋友拿去吧. 原文地址:http://www.jbxue.com/article/1 ...
- js中判断true和false的情况
- ue4 plugin的编译加载
插件Plugin: 本来应该是指一种纯以接口与外界打交道的程序模块,在同一接口背后可以有多种实现,更换实现完全不影响客户端代码(不用重编). 但是在ue4的世界里,插件似乎不是这个意思,仅仅是一种可以 ...
- js动态生成二维码图片
1.html代码 <div id="qrcode" style="width:200px; height:200px;position: fixed;bottom: ...
- AC算法 及python实现
零 导言 软件安全课上,老师讲了AC算法,写个博客,记一下吧. 那么AC算法是干啥的呢? ——是为了解决多模式匹配问题.换句话说,就是在大字符串S中,看看小字符串s1, s2,...有没有出现. AC ...
- Java自定义表单、自定义字段
最近想实现用户自定义数据库中的字段,我想大部分人第一想到的就是EAV(Entity-Attribute-Value),这种方式对于写一个小的毕业设计应该还可以使用,当然也有很多CMS系统采用这种方式, ...
- 了解Hadoop和大数据
1. 场景: 现在人产生数据越来越快,机器则更快,所以需要另外的一种处理数据的方法. 硬盘容量增加,但是性能没跟上,解决办法是将数据分到多块硬盘,然后同时读取. 问题: 硬件问题 -- 复 ...
- C++基础知识易错点总结(1)
1. 在C++中,不能被重载的运算符有: sizeof . 成员运算符 .* 成员指针运算符 :: 作用域运算符 ?: 条件运算符 2. C++语言多态性:编译时多态和运行时多态: 编译时多态可通过函 ...