[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. ...
随机推荐
- stealwatch里的安全功能——ETA结果会显示加密套件以及key长度,还有流量大小(例如41MB)
以后可以考虑的方向,在stealwatch里包含: ad Injector click fraud cryptocurrency miner exploit kit malicious adverti ...
- QPainter使用不同风格的QBrush来填充区域
效果图: void WgtText::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setRenderHint(QP ...
- Talend 数据转换
2个系统都有客户信息,产品信息. 要从一个系统a导出数据给另一个系统b用. 有2个方法. 1.在a系统的客户表,产品表加一个字段,记录b系统对应的ID,导出时直接用sql转换了. 2. 用ETL工具转 ...
- 放弃Dubbo,选择最流行的Spring Cloud微服务架构实践与经验总结
http://developer.51cto.com/art/201710/554633.htm Spring Cloud 在国内中小型公司能用起来吗?从 2016 年初一直到现在,我们在这条路上已经 ...
- nodejs安装 淘宝镜像
1◆ nodejs下载 2◆ 安装 3◆ 测试 4◆ 淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org 5 ...
- CString 转换为 wchar_t *
1.将CString转换为const char* CString str = _T("231222"); std::string strDp = CStringA(str); / ...
- mips编译器交叉编译openssl
1.下载源码: git clone https://github.com/openssl/openssl.git 2. 配置生成Makefile ./config no-asm shared --p ...
- Mysql 数据库意向锁意义
锁:对 “某种范围” 的数据上 “某种锁”1.“某种范围”:行.表 2.“某种锁”2.1 共享锁Shared Locks(S锁)1.兼容性:加了S锁的记录,允许其他事务再加S锁,不允许其他事务再加X锁 ...
- (C/C++学习笔记) 二十一. 异常处理
二十一. 异常处理 ● 异常的概念 程序的错误通常包括:语法错误.逻辑错误.运行异常. 语法错误指书写的程序语句不合乎编译器的语法规则,这种错误在编译.连接时由编译器指出. 逻辑错误是指程序能顺利运行 ...
- Cracking The Coding Interview 1.8
//Assume you have a method isSubstring which checks if one word is a substring of another. //Given t ...