国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 云梦县| 浦北县| 沽源县| 彩票| 安溪县| 南宁市| 洛宁县| 金山区| 桂平市| 资阳市| 乌苏市| 河津市| 南丰县| 沈丘县| 新晃| 海晏县| 三原县| 宜宾县| 从江县| 株洲市| 乐安县| 宜兰县| 桃源县| 宁津县| 安仁县| 永昌县| 新和县| 临西县| 西充县| 九龙县| 普安县| 河池市| 德保县| 莲花县| 宁武县| 舒兰市| 剑阁县| 西藏| 金坛市| 祁阳县| 淄博市|