24. Swap Nodes in Pairs
来源:互联网 发布:阿里云 混合云 编辑:程序博客网 时间:2024/06/06 07:26
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode swapPairs(ListNode head) {
if (head == null || head.next == null){
return head;
}
ListNode node = head.next;
head.next = swapPairs(head.next.next);
node.next = head;
return node;
}
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode swapPairs(ListNode head) {
if (head == null || head.next == null){
return head;
}
ListNode node = head.next;
head.next = swapPairs(head.next.next);
node.next = head;
return node;
}
}
使用递归即可
阅读全文
0 0
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24.Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs
- springboot注入bean
- Spring 整合 MyBatis
- 寻找Harris、Shi-Tomasi和亚像素角点
- php字符串查找strpos,strrpos,
- CSS3背景、渐变、蒙版
- 24. Swap Nodes in Pairs
- CSAPP Bomb Lab
- LabVIEW 视觉软件 发布部署 要点
- Android View事件分发机制 三 (Activity)
- CSAPP data Lab
- JAVA中日期 yyyy-MM-dd HH:mm:ss和yyyy-MM-dd hh:mm:ss的区别
- 小随笔:写一个基于几何生成方法的描边效果
- HashMap和TreeMap
- CSS3分栏、响应式布局