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. Django之路由分配系统

    前言: Django大致工作流程 1.客户端发送请求(get/post)经过web服务器.Django中间件. 到达路由分配系统 2.路由分配系统根据提取 request中携带的的url路径(path ...

  2. IDA 逆向工程 反汇编使用

    IDA pro 7.0版本 from:freebuf 用到的工具有IDA pro 7.0  ,被反汇编的是百度云(BaiduNetdisk_5.6.1.2.exe). 首先,IDA pro的长相如下: ...

  3. 随机数类Random

    我们来学习下,用来产生随机数的类Random,它也属于引用数据类型. 这个Random类,它可以产生多种数据类型的随机数,在这里我们主要介绍生成整数与小数的方式. l  方法简介 public int ...

  4. Node.js概要

    Node.js是一个Javascript运行环境(runtime). Node.js对一些特殊用例进行了优化,提供了替代的API,使得V8在非浏览器环境下运行得更好. Node.js是一个基于Chro ...

  5. Jquery如何禁止鼠标右键菜单

    jquery中使用contextmenu事件,如果返回true,则允许右键菜单:如果返回false,则禁止右键菜单 导入文件 <script type="text/javascript ...

  6. jackSon注解– @JsonInclude 注解不返回null值字段

    @Data @JsonInclude(JsonInclude.Include.NON_NULL) public class OrderDTO { private String orderId; @Js ...

  7. linux查看在线用户并踢出用户

    linux查看在线用户并踢出用户 1.查看在线用户 w [root@dbserver01 ~]# w 16:45:04 up 16 days, 8:48, 1 user, load average: ...

  8. Grafana展示報表數據的配置(二)

    一.Grafana以圖表的形式展示KPI報表的結果數據1.按照日期顯示數據達標量與未達標量2.顯示當前報表的最大值.最小值.平均值.總量3.報表結果數據的鏈接分享與頁面嵌入,用戶無需登錄直接訪問報表統 ...

  9. MyBatis逆向工程:根据table生成Model、Mapper、Mapper.xml

    逆向工程工具 下载地址:https://download.csdn.net/download/zhutouaizhuwxd/10779140 1.工程导入Eclipse  2.运行MainUI.jav ...

  10. vue.set动态新增对象属性,触发dom渲染

    当我们给一个props或者data中被观测的对象添加一个新的属性的时候,不能直接添加,必须使用Vue.set方法 /** * ==== 选择产品 ==== * 因为vue实现双向数据绑定的机制是数据劫 ...