LeetCode 23. Swap Nodes in Pairs
来源:互联网 发布:sql中查询重复的数据 编辑:程序博客网 时间:2024/06/08 03:32
用head, prev, cur三个指针维护
依题意做即可。
代码:
class Solution {public: ListNode *swapPairs(ListNode *head) { ListNode *cur = head, *prev; while(cur!=NULL && cur->next!=NULL) { if (cur == head) { auto next = cur->next->next; head = head->next; head->next = cur; cur->next = next; } else { auto next = cur->next->next; prev->next = cur->next; cur->next->next = cur; cur->next = next; } prev = cur; cur = cur->next; } return head; }};
0 0
- LeetCode 23. Swap Nodes in Pairs
- LeetCode:Swap Nodes in Pairs
- LeetCode: Swap Nodes in Pairs
- [Leetcode] Swap Nodes in Pairs
- LeetCode : Swap Nodes in Pairs
- [LeetCode] Swap Nodes in Pairs
- Leetcode: Swap nodes in pairs
- [LeetCode]Swap Nodes in Pairs
- [LeetCode]Swap Nodes in Pairs
- LeetCode-Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- LeetCode | Swap Nodes in Pairs
- 【leetcode】Swap Nodes in Pairs
- Leetcode: Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- 【LeetCode】Swap Nodes in Pairs
- Leetcode: Swap Nodes in Pairs
- Leetcode Swap Nodes in Pairs
- 旋转卡壳(卡尺)算法
- 解决 Xcode下使用公用静态库,出现的"Duplicate Symbol"错误
- 【实用随记】失焦和双击
- Hp-ux下网络IP配置
- 废暮握匚九蓝肆疾文卮把币逃凑墙
- LeetCode 23. Swap Nodes in Pairs
- 【android】null pointer exception
- CABAC 学习(4)概率更新模型分析
- 微铺子点单系统,微信订餐平台领导者。微信点餐,微铺子
- javascript去除空格
- Uva 1471 Defense Lines(线段树)
- Impala与Hive的比较
- vs2010下使用nmake编译库的注意事项
- Android自定义进度条