[LeetCode&Python] Problem 206. Reverse Linked List
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的更多相关文章
- 【leetcode❤python】206. Reverse Linked List
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# s ...
- [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 ...
- [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 ...
- [LeetCode&Python] Problem 917. Reverse Only Letters
Given a string S, return the "reversed" string where all characters that are not a letter ...
- 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 ...
- 链表 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 反向链表
Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. ...
随机推荐
- 把旧系统迁移到.Net Core 2.0 日记(10) -- EF core 和之前版本多对多映射区别
EF Core 现在不支持多对多映射,只能做2个一对多映射. 比如Product和Category 我现在定义Product和Category是多对多关系. 那么实体定义如下: public clas ...
- 把旧系统迁移到.Net Core 2.0 日记(4) - 使用EF+Mysql
因为Mac 不能装SqlServer, 所以把数据库迁移到MySql,然后EntityFramework要改成Pomelo.EntityFrameworkCore.MySql 数据库迁移时,nvarc ...
- input text 在苹果微信浏览器中有上上阴影
box-shadow:0px 0px 0px rgba(0,0,0,0); -webkit-appearance:none;
- 蓝桥杯—ALGO-2 最小最大公倍数
问题描述已知一个正整数N,问从1~N中任选出三个数,他们的最小公倍数最大可以为多少. 输入格式输入一个正整数N. 输出格式输出一个整数,表示你找到的最小公倍数.样例输入9样例输出504数据规模与约定1 ...
- SRAM、DRAM、SDRAM、DDR、DDR2、DDR3
RAM可分为SRAM(Static RAM/静态存储器)和DRAM(Dynamic RAM/动态存储器).SRAM是利用双稳态触发器来保存信息的,只要不掉电,信息是不会丢失的.SRAM存储元件所用MO ...
- jenkins部署web项目到tomcat(五)
(1)maven构建web项目 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...
- information_schema
views 视图表,查看当前数据库有哪些视图 select table_catalog,table_schema,table_name,is_updatable,definer,security_ty ...
- Mysql高可用
一.二进制日志 二进制日志,记录所有对库的修改,如update.修改表结构等等 需要开启二进制日志的原因: 1.主从复制都是通过二进制日志进行.主库写二进制日志,传输到从库,从库replay二进制日志 ...
- ASPNET MVC5 根 core
Asp.Net Core MVC的开源地址:https://github.com/aspnet/Mvc Asp.net MVC的开源地址:http://aspnetwebstack.codeplex. ...
- 7.9 C++ STL算法
参考:http://www.weixueyuan.net/view/6406.html 总结: STL提供了大量操作容器的算法,这些算法大致可以分为:排序.搜索.集合运算.数值处理和拷贝等,这些算法的 ...