# 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
        """
        end = head
        for i in range(n-1):
            end = end.next
        prev = None
        start = head
        while end != None:
            if end.next == None:
                break
            prev = start
            end = end.next
            start = start.next
            
        if prev == None:
            return start.next
        prev.next = start.next
        return head

7b6e6300c6a5adbc4eee94e90a8998e07266e3c0
<mask token>

class Solution(object):
    <mask token>

class Solution(object):

    def removeNthFromEnd(self, head, n):
        """
        :type head: ListNode
        :type n: int
        :rtype: ListNode
        """
        end = head
        for i in range(n - 1):
            end = end.next
        prev = None
        start = head
        while end != None:
            if end.next == None:
                break
            prev = start
            end = end.next
            start = start.next
        if prev == None:
            return start.next
        prev.next = start.next
        return head

# 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
        """
        end = head
        for i in range(n-1):
            end = end.next
        prev = None
        start = head
        while end != None:
            if end.next == None:
                break
            prev = start
            end = end.next
            start = start.next
            
        if prev == None:
            return start.next
        prev.next = start.next
        return head
