【easy】206. Reverse Linked List 链表反转
链表反转,一发成功~
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseList(ListNode* head) {
//就地反转
if(head == NULL || head ->next == NULL)
return head;
ListNode* pre = head;
ListNode* cur = head->next;
ListNode* nxt = NULL; while (cur){
nxt = cur->next;
cur->next = pre;
pre = cur;
cur = nxt;
}
head->next = NULL;
head = pre;
return head;
}
};
【easy】206. Reverse Linked List 链表反转的更多相关文章
- [LeetCode]206. Reverse Linked List(链表反转)
Reverse a singly linked list. click to show more hints. Subscribe to see which companies asked this ...
- Leetcode 206 Reverse Linked List 链表
将单向链表反转 完成如图操作,依次进行即可 1 2 3 /** * Definition for singly-linked list. * struct ListNode { * int val; ...
- LeetCode 206 Reverse Linked List(反转链表)(Linked List)(四步将递归改写成迭代)(*)
翻译 反转一个单链表. 原文 Reverse a singly linked list. 分析 我在草纸上以1,2,3,4为例.将这个链表的转换过程先用描绘了出来(当然了,自己画的肯定不如博客上面精致 ...
- 【LeetCode每天一题】Reverse Linked List(链表反转)
Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL ...
- [LeetCode] 206. Reverse Linked List ☆(反转链表)
Reverse Linked List 描述 反转一个单链表. 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3-> ...
- 链表 206 Reverse Linked List, 92,86, 328, 2, 445
表不支持随机查找,通常是使用next指针进行操作. 206. 反转链表 /** * Definition for singly-linked list. * struct ListNode { * i ...
- 206. Reverse Linked List【easy】
206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed eit ...
- leetcode 206. Reverse Linked List(剑指offer16)、
206. Reverse Linked List 之前在牛客上的写法: 错误代码: class Solution { public: ListNode* ReverseList(ListNode* p ...
- 206. Reverse Linked List - LeetCode
Question 206. Reverse Linked List Solution 题目大意:对一个链表进行反转 思路: Java实现: public ListNode reverseList(Li ...
随机推荐
- (转)lwip TCP client & FreeRTOS 打开TCP 的 保活机制 LWIP_TCP_KEEPALIVE==1
参考大神教程:http://blog.sina.com.cn/s/blog_62a85b950101aw8x.html 老衲五木 :http://blog.sina.com.cn/s/blog_6 ...
- day4(分支结构,循环结构,for循环,九九乘法表)
一:复习 ''' 1.变量名命名规范 -- 1.只能由数字.字母 及 _ 组成 -- 2.不能以数字开头 -- 3.不能与系统关键字重名 -- 4._开头有特殊含义 -- 5.__开头__结尾的变量, ...
- 关于JAVA中string直接初始化赋值和new的区别,是否可以联系到int[]的情况
String str1 = "ABC"; String str2 = new String("ABC"); String str1 = “ABC”;可能创建一个 ...
- ReSharper 2017破解详细方法:
VS里面,打开ReSharper的注册窗口:ReSharper ——> Help ——> License Information... Use License Server,右侧加号,点击 ...
- Netty 5 io.netty.util.IllegalReferenceCountException 异常
异常信息 io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1 原因 handler 继承了 SimpleChan ...
- saltstack运维软件
一.saltstack介绍 1.介绍 SaltStack管理工具允许管理员对多个操作系统创建一个一致的管理系统,包括VMware vSphere环境. SaltStack是一个服务器基础架构集中化管理 ...
- Qt QWidget
原文: https://www.cnblogs.com/muyuhu/archive/2012/10/26/2741184.html QWidget 类代表一般的窗口,其他窗口类都是从 QWidget ...
- [OI]Noip 2018总结(普及)
考砸了,还有原谅我代码十分有限的可读性. 一个人的真正伟大之处就在于他能够认识到自己的渺小.——保罗 从一年前初一九月到现在18年10月接触OI已经有一年了.几次模拟赛也自我感觉良好,都过了一等的线, ...
- Codeforces484 A. Bits
题目类型:位运算 传送门:>Here< 题意:求区间\([L,R]\)内二进制中1的个数最多的那个数,如果有多解输出最小解 解题思路 想了15min就一遍A了 我们可以贪心地在\(L\)的 ...
- 爬虫 BeatifulSoup 模块
BeatifulSoup 模块 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库 安装 pip install beautifulsoup4 解析器下载 ...