国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

LeetCode 24. Swap Nodes in Pairs

2019-11-08 03:16:28
字體:
供稿:網(wǎng)友

Given 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.

answer:

class Solution {public:    ListNode* swapPairs(ListNode* head) {        ListNode* first = head;        ListNode* second ;        if(first == NULL) return head;        second = first->next;        int temp;        while(second != NULL){            temp = first->val;            first->val = second->val;            second->val = temp;            first = (first->next)->next;            if(first == NULL) return head;            second = first->next;        }        return head;    }};


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 镇坪县| 莱芜市| 桃园市| 策勒县| 福清市| 尼勒克县| 肇州县| 大石桥市| 江津市| 桓台县| 柳河县| 怀化市| 六安市| 尚义县| 灵川县| 武穴市| 德安县| 平果县| 茂名市| 湖口县| 博白县| 龙山县| 增城市| 紫阳县| 秦安县| 井陉县| 安国市| 娄烦县| 客服| 河津市| 台东市| 军事| 浦江县| 庆城县| 大田县| 西宁市| 阿尔山市| 德昌县| 郴州市| 克什克腾旗| 湟中县|