leetcode_24. Swap Nodes in Pairs C++
来源:互联网 发布:淘宝手链店 编辑:程序博客网 时间:2024/06/16 13:00
好艰难第一题,不得不说我这蹩脚的coding能力,太久不coding居然连该用->还是.都晕晕乎乎了。 已服我。
You are here! Your runtime beats 1.83% of cppsubmissions. 好弱!!!
<span style="font-size:18px;">/** * 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) { ListNode *helper; helper->val = 0;helper->next = head; ListNode *pre = helper;while(head && head->next){ListNode *t = head->next->next; pre->next = head->next; pre->next->next = head; head->next = t; pre = head; head =t; } return helper->next; }};</span>
- 对链表定义成指针时,对指针操作统一使用->,不管是listNode的变量还是下一个ListNode;
- 就指针操作经常用到的技巧: 助指针作为表头,链表中比较常用的小技巧,因为这样可以避免处理head的边界情况;
0 0
- LeetCode_24---Swap Nodes in Pairs
- leetcode_24. Swap Nodes in Pairs C++
- leetcode_24. Swap Nodes in Pairs 单链表中成对交换结点位置
- leetcode: Swap Nodes in Pairs (C++)
- Swap Nodes in Pairs(C语言)
- 【LeetCode-24】Swap Nodes in Pairs(C++)
- 【C++】【LeetCode】24. Swap Nodes in Pairs
- Leetcode c语言-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
- 数据库理论-设计范式
- java_singlton模式
- SQLiteDatabase
- 四个人脸数据集,matlab格式 Four face databases in matlab format
- linux 多线程学习一:互斥
- leetcode_24. Swap Nodes in Pairs C++
- bzoj1149/2895 [JSOI2009]球队收益
- 二维码扫描,生成
- 剑指offer05--用两个栈来模拟队列
- 特征学习的matlab代码和数据集 Matlab Codes and Datasets for Feature Learning
- URL路径中传参
- HDOJ/HDU 2561 第二小整数(水题~排序~)
- JAVA枚举使用详解
- bzoj 4592: [Shoi2015]脑洞治疗仪