Leetcode Swap Nodes in Pairs
来源:互联网 发布:游族网络 林奇 编辑:程序博客网 时间:2024/05/04 10:34
这题代码写得太丑了。实在不想提。
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *swapPairs(ListNode *head) { // Note: The Solution object is instantiated only once and is reused by each test case. if(head == NULL || head->next == NULL) return head; ListNode *cur = NULL, *next = NULL, *nHead = NULL, *tmp = NULL, *prev = NULL; for(cur = head; cur != NULL;){ if(cur->next != NULL) next = cur->next->next; else next = NULL; tmp = cur->next; if(nHead == NULL) nHead = tmp; if(tmp != NULL) tmp->next = cur; cur->next = next; if(prev != NULL){ if(tmp != NULL) prev->next = tmp; else prev->next = cur; } prev = cur; cur = next; } return nHead; }};
- 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
- LeetCode Swap Nodes in Pairs
- 电容触摸屏驱动---基于FT5406
- 浮点型数据存储方式分析
- Java中反射的运用
- hdu-4548
- ios7 新特性
- Leetcode Swap Nodes in Pairs
- Qt学习第三天
- phpstorm密钥
- sgu 507 (启发式合并)
- 电池电量转换参考
- ubuntu 升级php5.3到php5.5
- socket通信中select函数的使用和解释
- 使用旋转掩膜的平均
- [MATLAB]从已知矩阵中取出子阵