码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode 19-> Remove Nth Node From End of List

时间:2019-03-13 19:44:01      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:code   linked   play   spl   type   tno   splay   style   else   

 

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def removeNthFromEnd(self, head,n):
        """
        :type head: ListNode
        :type n: int
        :rtype: ListNode
        """
        def remove(h,n):
            if h.next:
                c = remove(h.next,n)
            else:
                return 1
            if c == n:
                h.next = h.next.next
            return c + 1
        result = ListNode(0)
        result.next = head
        remove(result,n)
        return result.next

 

leetcode 19-> Remove Nth Node From End of List

标签:code   linked   play   spl   type   tno   splay   style   else   

原文地址:https://www.cnblogs.com/sea-stream/p/10525080.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!