【leetcode】24. Swap Nodes in Pairs
来源:互联网 发布:淘宝价格模板怎么改 编辑:程序博客网 时间:2024/06/18 06:44
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.
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode swapPairs(ListNode head) { if (head==null){ return null; } if(head.next==null){ return head; } ListNode temp=head.next; head.next=swapPairs(temp.next); temp.next=head; return temp; }}
0 0
- [LeetCode]24.Swap Nodes in Pairs
- 24. Swap Nodes in Pairs Leetcode Python
- LeetCode --- 24. Swap Nodes in Pairs
- LeetCode 24.Swap Nodes in Pairs
- [Leetcode] 24. Swap Nodes in Pairs
- 【LeetCode】24.Swap Nodes in Pairs
- [leetcode] 24.Swap Nodes in Pairs
- **LeetCode 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs LeetCode
- leetcode 24. Swap Nodes in Pairs
- leetcode 24. Swap Nodes in Pairs
- LeetCode--24. Swap Nodes in Pairs
- leetcode 24. Swap Nodes in Pairs
- 【LeetCode】24. Swap Nodes in Pairs
- [leetcode] 24. Swap Nodes in Pairs
- LeetCode 24. Swap Nodes in Pairs
- LeetCode-24.Swap Nodes in Pairs
- LeetCode 24. Swap Nodes in Pairs
- Oracle数据库编码修改
- 用 Flask 来写个轻博客 (21) — 结合 reCAPTCHA 验证码实现用户注册与登录
- 三倍角正切公式在平面几何解题中的应用
- 禁止CloudStack删除Xenserver原有虚拟机
- Spring依赖注入学习总结
- 【leetcode】24. Swap Nodes in Pairs
- Difference between break and return
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- Android安全之旅系列博客导读
- 【Leetcode】22. Generate Parentheses
- Spark2.0.1 on yarn with hue 集群安装部署(八)hue+livy+spark整合
- 重叠I/O完成例程模型如何同时投递WSARecv和WSASend
- 练习3.1
- 重拾python 二十一