LeetCode 24. Swap Nodes in Pairs
来源:互联网 发布:java软件工程师就业班 编辑:程序博客网 时间:2024/06/13 19:47
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.
answer:
class Solution {public: ListNode* swapPairs(ListNode* head) { ListNode* first = head; ListNode* second ; if(first == NULL) return head; second = first->next; int temp; while(second != NULL){ temp = first->val; first->val = second->val; second->val = temp; first = (first->next)->next; if(first == NULL) return head; second = first->next; } return head; }};
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
- iOS设计模式-工厂方法
- 苹果审核广告选择
- mp4文件播放不了
- mybatisgeneratormodel-mybatis逆向工程
- table中th内容水平垂直居中
- LeetCode 24. Swap Nodes in Pairs
- JAVA--HashCode 基础(判断对象是否相等)
- Ural 2069 Hard Rock
- Android TextSwitcher 文本切换器
- Qt使用QStackedWidget实现堆栈窗口
- UNIX高级编程-高级I/O
- 主分区 逻辑分区
- [数据表设计] - 商品模型数据架构图
- Java集合框架总结