【LeetCode24】. Swap Nodes in Pairs Add to List
来源:互联网 发布:数据统计管理制度pdf 编辑:程序博客网 时间:2024/05/06 18:00
/*****************************************LeetCode24. Swap Nodes in Pairs Add to ListDescription Submission SolutionsTotal Accepted: 149955Total Submissions: 400577Difficulty: MediumContributors: AdminGiven 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.**************************************/ListNode* swapPairs(ListNode* head){ if (head == NULL||head->next == NULL )return head;ListNode preHead(0);preHead.next = head; ListNode *pre = &preHead;ListNode *cur = pre->next;ListNode *end = cur->next->next; while (cur!=NULL && cur->next!=NULL){pre->next = cur->next;cur->next = cur->next->next;pre->next->next = cur; pre = cur;cur = cur->next;} return preHead.next; }
0 0
- 【LeetCode24】. Swap Nodes in Pairs Add to List
- [LeetCode24]Swap Nodes in Pairs
- leetcode24:Swap Nodes in Pairs
- leetCode24:Swap Nodes in Pairs
- leetcode24:Swap Nodes in Pairs
- LeetCode24. Swap Nodes in Pairs
- leetcode24:Swap Nodes in Pairs
- leetcode24~Swap Nodes in Pairs
- LeetCode24. Swap Nodes in Pairs
- LeetCode24. Swap Nodes in Pairs
- leetcode24. Swap Nodes in Pairs
- 【LeetCode24】Swap Nodes in Pairs题解
- LeetCode24 Swap Nodes in Pairs 成对交换链表节点
- LeetCode24. Swap Nodes in Pairs简单到一次性通过
- LeetCode24 Swap Nodes in Pairs 25. Reverse Nodes in k-Group详解
- Posts Tagged 【List】Swap Nodes in Pairs
- [leetcode][list] Swap Nodes in Pairs
- 24. Swap Nodes in Pairs(Linked List)
- 将一个十进制数n转化为B进制数。
- 完整验证&密码的显示与隐藏&验证码
- 动态规划之01背包问题
- C#操作EXCEL
- 二叉搜索树的简单说明
- 【LeetCode24】. Swap Nodes in Pairs Add to List
- jsp中<%%> 与<%!%> , <%%>与<%=%>的区别是什么?
- 笔记本电脑进入BIOS设置快捷键大全
- The security settings could not be applied to the database because the connection has failed w
- 将数据集做成VOC2007格式用于Faster-RCNN训练
- Reverse Nodes in k-Group-LeetCode
- 高并发生成订单号
- VS快捷键
- Android绘画关卡地图