Swap Nodes in Pairs
来源:互联网 发布:获取网页限制数据 编辑:程序博客网 时间:2024/06/03 14:39
题目大意:链表中的两个数两两交换
/** * 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) { if(head == NULL || head->next == NULL) { return head; } ListNode *result = head->next; ListNode *preNode = NULL, *curNode = head, *nextNode = head->next; while(curNode != NULL && nextNode != NULL) { curNode->next = nextNode->next; nextNode->next = curNode; if(preNode != NULL) { preNode->next = nextNode; } preNode = curNode; curNode = curNode->next; if(curNode != NULL) { nextNode = curNode->next; } } return result; }};
1 0
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes In Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- 芒果iOS开发之史上最全的面试题汇总一
- 判断两个链表是否相交并找出交点
- 有关Intent的一些简介
- 关于部分新手用笔记本学习Linux时按下ctrl+alt+F1~F6没反应的问题
- java时间转换
- Swap Nodes in Pairs
- void main(void x)两个void的区别 -----void与void*详解
- Qt编程18:Qt调色板QPalette的使用
- intel Threading Building Blocks 入门 (基本算法)
- 关于TbSchedule任务调度管理框架的整合部署
- 智能电视-时序控制(T-CON)电路的组成
- ACCESS 日期函數 常用函數
- android应用开发全程实录-你有多熟悉listview?
- IOS学习步骤