美文网首页
lintcode 35. 翻转链表

lintcode 35. 翻转链表

作者: cuizixin | 来源:发表于2018-08-31 21:43 被阅读1次

难度:容易

1. Description

35. 翻转链表

2. Solution

  • python
    时间复杂度O(n)
"""
Definition of ListNode

class ListNode(object):

    def __init__(self, val, next=None):
        self.val = val
        self.next = next
"""

class Solution:
    """
    @param head: n
    @return: The new head of reversed linked list.
    """
    def reverse(self, head):
        # write your code here
        pre = None
        while(head):
            tmp = head.next
            head.next = pre
            pre = head
            head = tmp
        return pre

3. Reference

  1. https://www.lintcode.com/problem/reverse-linked-list/description

相关文章

  • lintcode 35. 翻转链表

    难度:容易 1. Description 2. Solution python时间复杂度 3. Reference...

  • lintcode 35. 翻转链表

    难度:简单 1. Description 2. Solution python 3. Reference http...

  • lintcode 翻转链表

    三十五题为翻转一个单链表,三十六题为翻转链表中第m个节点到第n个节点的部分样例给出链表1->2->3->4->5-...

  • 35. 翻转链表

    描述 翻转一个链表 样例 给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null 挑...

  • 35. 翻转链表

    样例给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null 复制链表节点,一个一个放...

  • LintCode 练习代码

    35.翻转链表 165. 合并两个排序链表 96. 链表划分 166. 链表倒数第n个节点 java语言一次循环定...

  • lintcode 32 翻转链表

    翻转一个链表 样例:给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null

  • lintcode 32 翻转链表

    思路image.png每次遍历的节点拿到最前面,作为新的head节点。 那么2节点的next地址不能丢了。p.ne...

  • LintCode 翻转链表 II

    题目 翻转链表中第m个节点到第n个节点的部分 注意事项m,n满足1 ≤ m ≤ n ≤ 链表长度 代码

  • 35.翻转链表(Python)

    描述给定一个链表1->2->3->null,这个翻转后的链表为3->2->1->null。 Solution思路:...

网友评论

      本文标题:lintcode 35. 翻转链表

      本文链接:https://www.haomeiwen.com/subject/pnwewftx.html