100%,python,list solution


  • 0
    L

    ...
    class Solution(object):
    def removeNthFromEnd(self, head, n):
    """
    :type head: ListNode
    :type n: int
    :rtype: ListNode
    """
    collection=list();
    ptr=head;
    collection.append(ptr)
    while ptr.next is not None:
    collection.append(ptr.next)
    ptr=ptr.next
    length=len(collection);
    print length
    if length-n==0 and length>1:
    return collection[1]
    elif length-n==0 and length==1:
    return None
    elif length-n+1<length and length-n-1>-1:
    collection[length-n-1].next=collection[length-n+1]
    return head
    elif length-n==length-1:
    collection[length-2].next=None
    return head
    ...


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.