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. [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)

    [Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...

  2. elasticsearch设置外部可访问

    修改/config/elasticsearch.yml文件,增加如下配置: network.host: 0.0.0.0 浏览器访问http://192.168.17.134:9200/效果: 实际操作 ...

  3. CAD(布置厨洁具)(尺寸标注)5.12

    "TYTK"打开图库,找到平面厨具和洁具.双击选中的厨具,A可以不停旋转90度.给厨具选取正确的位置.画出灶台线,同理画出卫生间的家具.绘制出洗脸台的平台.浴缸的平台. 尺寸标注: ...

  4. 服务消费和负载(Ribbon)

    使用RestTemplate调用服务 在上一篇教程中,我们是这样调用服务的,先通过 LoadBalancerClient 选取出对应的服务,然后使用 RestTemplate 进行远程调用. Load ...

  5. printf以%d形式输出浮点数的问题

    若运行时从键盘上输入9876543210l,则下面程序的输出结果是 int main(){ int a;float b,c; scanf("%2d%3f%4f",&a,&a ...

  6. netty]--最通用TCP黏包解决方案

    netty]--最通用TCP黏包解决方案:LengthFieldBasedFrameDecoder和LengthFieldPrepender 2017年02月19日 15:02:11 惜暮 阅读数:1 ...

  7. @ResponseBody中文乱码解决方案

    java web项目,使用了springmvc4.0,用@ResponseBody返回中文字符串,乱码$$ 本以为很简单的问题,不过也找了一个小时. 网上有说这样配置的: <mvc:annota ...

  8. 各个版本的jee(servlet,jsp)对应的web.xml的模板

    参考链接: https://yutuo.net/archives/7048a006eeb2ac85.html

  9. Linux 目录配置标准:FHS

    目录 应放置内容 /bin 和/user/目录下的/bin/都是用来保存的系统命令 /sbin 和/user/目录下的/sbin是用来保存root的系统命令 /boot 这个目录主要放置开机所用的文件 ...

  10. java.util.concurrent ThreadPoolExecutor源码分析

    实现的接口:Executor, ExecutorService 子类:ScheduledThreadPoolExecutor 这类为java线程池的管理和创建,其中封装好的线程池模型在Executor ...