将单向链表反转

完成如图操作,依次进行即可

1

2

3

 /**
* 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) {
ListNode* now = head;
head = NULL;
while(now){
ListNode* tnow= now;
now = now->next;
tnow->next = head;
head = tnow;
}
return head;
}
};

Leetcode 206 Reverse Linked List 链表的更多相关文章

  1. [LeetCode]206. Reverse Linked List(链表反转)

    Reverse a singly linked list. click to show more hints. Subscribe to see which companies asked this ...

  2. leetcode 206. Reverse Linked List(剑指offer16)、

    206. Reverse Linked List 之前在牛客上的写法: 错误代码: class Solution { public: ListNode* ReverseList(ListNode* p ...

  3. [LeetCode] 206. Reverse Linked List 反向链表

    Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. ...

  4. [LeetCode] 206. Reverse Linked List ☆(反转链表)

    Reverse Linked List 描述 反转一个单链表. 示例: 输入: 1->2->3->4->5->NULL    输出: 5->4->3-> ...

  5. 迭代和递归 - leetcode 206. Reverse Linked List

    Reverse Linked List,一道有趣的题目.给你一个链表,输出反向链表.因为我用的是JavaScript提交,所以链表的每个节点都是一个对象.例如1->2->3,就要得到3-& ...

  6. C++版 - 剑指offer 面试题16:反转链表(Leetcode 206: Reverse Linked List) 题解

    面试题16:反转链表 提交网址: http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca?tpId=13&tqId= ...

  7. LeetCode 206. Reverse Linked List (倒转链表)

    Reverse a singly linked list. 题目标签:Linked List 题目给了我们一个链表,要求我们倒转链表. 利用递归,新设一个newHead = null,每一轮 把下一个 ...

  8. LeetCode 206. Reverse Linked List倒置链表 C++

    Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4-> ...

  9. LeetCode 206 Reverse Linked List(反转链表)(Linked List)(四步将递归改写成迭代)(*)

    翻译 反转一个单链表. 原文 Reverse a singly linked list. 分析 我在草纸上以1,2,3,4为例.将这个链表的转换过程先用描绘了出来(当然了,自己画的肯定不如博客上面精致 ...

随机推荐

  1. POJ 3281 Dining

    Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and dri ...

  2. hdu 5748(LIS) Bellovin

    hdu 5748 Peter有一个序列a1,a2,...,ana_1,a_2,...,a_na​1​​,a​2​​,...,a​n​​. 定义F(a1,a2,...,an)=(f1,f2,...,fn ...

  3. Log4j基本用法

    基本使用方法: Log4j由三个重要的组件构成:日志信息的优先级,日志信息的输出目的地,日志信息的输出格式.日志信息的优先级从高到低有ERROR.WARN.INFO.DEBUG,分别用来指定这条日志信 ...

  4. 专题:『Channel Bonding/team』——EXPERIMANTAL!!!

    Linux内核支持的多网卡聚合方法——bond.team bond 优点:经过长时间的实践检验,具有较高的稳定性:kernel-2.4及以上内核均广泛支持 缺点:需要通过sysfs或发行版定制的网卡配 ...

  5. perl 对源文件内容修改 方法整理

    1, 利用Tie::File模块来直接对文件内容进行修改. #!/usr/bin/perl -w my $std="F160"; my $fast="FAST" ...

  6. 下载python标准库--python

    #coding:utf-8 import urllib2 import os,sys from BeautifulSoup import BeautifulSoup # For processing ...

  7. [Chapter 3 Process]Practice 3.12 Including the initial parent process, how many processes are created by the program shown in Figure 3.32?

    3.12 Including the initial parent process, how many processes are created by the program shown in Fi ...

  8. linux 下 jdk+tomcat+mysql 的 jsp 环境搭建

    JDK 在 linux 下安装 1.          把安装文件放在 /opt 下,并执行 [root@localhost opt]# ./jdk-1_5_0_06-linux-i586.bin 并 ...

  9. 推荐一个C语言学习教程

    Linux C编程一站式学习 http://learn.akae.cn/media/index.html

  10. 写在Ruby之前。

    jeiao: 入行程序员也有一年的时间,入门的时候学的Java,在公司写了大半年的Java,也主要是Web方向,使用过struts2 做过项目,后来又用SSH实现了一遍,感觉就那么点意思,因为公司规模 ...