Reverse a singly linked list.

Example:

Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None class Solution(object):
def reverseList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
if head:
if head.next is not None:
s=self.reverseList(head.next)
head.next.next=head
head.next=None
return s
else:
return head
else:
return head

  

[LeetCode&Python] Problem 206. Reverse Linked List的更多相关文章

  1. 【leetcode❤python】206. Reverse Linked List

    # Definition for singly-linked list.# class ListNode(object):#     def __init__(self, x):#         s ...

  2. [LeetCode&Python] Problem 557. Reverse Words in a String III

    Given a string, you need to reverse the order of characters in each word within a sentence while sti ...

  3. [LeetCode&Python] Problem 541. Reverse String II

    Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...

  4. [LeetCode&Python] Problem 917. Reverse Only Letters

    Given a string S, return the "reversed" string where all characters that are not a letter  ...

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

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

  6. 206. Reverse Linked List - LeetCode

    Question 206. Reverse Linked List Solution 题目大意:对一个链表进行反转 思路: Java实现: public ListNode reverseList(Li ...

  7. 链表 206 Reverse Linked List, 92,86, 328, 2, 445

    表不支持随机查找,通常是使用next指针进行操作. 206. 反转链表 /** * Definition for singly-linked list. * struct ListNode { * i ...

  8. 206. Reverse Linked List【easy】

    206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed eit ...

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

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

随机推荐

  1. SourceInsight 4重启之后文件变只读无法编辑

    SourceInsight4.0在导入代码后,用起来没问题,第二天,再开启sourceInsight,结果所有文件变成只读了,不能编辑,标签前面也有了叹号. 百度一下,有人说是版本控制的问题,但是sv ...

  2. asp.net中javascript与后台c#交互

    asp.net中javascript与后台c#交互 作者:熊猫大叔 字体:[增加 减小] 类型:转载 时间:2015-10-23我要评论,出处:http://www.jb51.net/article/ ...

  3. python3 爬取简书30日热门,同时存储到txt与mongodb中

    初学python,记录学习过程. 新上榜,七日热门等同理. 此次主要为了学习python中对mongodb的操作,顺便巩固requests与BeautifulSoup. 点击,得到URL https: ...

  4. day041 前端HTML CSS基本选择器(未整理完毕)

    标签: <b> :加粗 <i> :倾斜体 <u>: 下划线 <s>: 删除线 <p>:段落 <h1> - <h6> ...

  5. 程序从sqlserver2008搬家到MySQL5.6

    1.数据表结构的搬家 SqlServer的建表sql语句在MySQL中肯定不能运行 这里使用转换工具 下载地址: https://download.csdn.net/download/zhutouai ...

  6. EF-一对一关系

    针对关系型数据库来说,需要明了每个对象之间的关系. 它们之间的关系有: 1.一对一(1:1):一个学生只能拥有一张身份证,一张身份证只能属于一个学生: 2.一对多(1:N):一个学生可以拥有几本书,而 ...

  7. [Leetcode 392]判断子序列 Is Subsequence

    [思路] 判断s是否为t的子串,所以length(s)<=length(t).于是两个指针,一次循环. 将s.t转换为数组p1.p2. i为过程中s的匹配长度. i=0空串,单独讨论返回true ...

  8. Cracking The Coding Interview 1.5

    //原文: // // Write a method to replace all spaces in a string with '%20'. // #include <iostream> ...

  9. 深入理解java虚拟机----java技术体系(一)

    1.java技术体系 举例: class文件格式:如下图所示,java源代码可以根据不同的编译器可以编译成不同的代码.即可以自定义语言规范比如beanshell,并编写代码; 然后自己编写java编译 ...

  10. MyEclipse教程:使用UML创建模块库——第二部分(一)

    MyEclipse 在线订购年终抄底促销!火爆开抢>> [MyEclipse最新版下载] UML2建模文件存储在建模存储库中,建模可用于生成Java代码,或者可以从代码生成模型. 本教程介 ...