24. Swap Nodes in Pairs LeetCode
来源:互联网 发布:淘宝充气娃娃实际拍图 编辑:程序博客网 时间:2024/05/18 00:50
题意:给出一个链表,链表的节点成对交换,也就是1和2换,3和4换。。。n - 1和n换。
题解:模拟即可,增加一个虚拟头结点。
class Solution {public: ListNode* swapPairs(ListNode* head) { ListNode *t = new ListNode(0); ListNode *temp; t->next = head; temp = t; while(temp->next && temp->next->next) { ListNode *tt = temp->next; ListNode *ttt = temp->next->next; temp->next = ttt; tt->next = ttt->next; ttt->next = tt; temp = temp->next->next; } return t->next; }};
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
- 46. Permutations LeetCode
- USACO Milking Cows 解题日志
- K-近邻分类算法(监督式)
- HDFS详细讲解
- poj 2378 简单树形dp
- 24. Swap Nodes in Pairs LeetCode
- Git教程
- BZOJ 3306|树|树链剖分
- 1031. 查验身份证
- Android 的性能 IV-多线程的性能
- 64. Minimum Path Sum LeetCode
- Ubuntu 12.04LTS 直接蓝牙A2DP操作
- GWPY 引力波
- C#遍历文件夹,只需一句话