text: class ListNode(object):
      def __init__(self, x):
          self.val = x
          self.next = None
  
  
  class Solution:
      def removeNthFromEnd(self, head, n):
          if not head:
              return
          fast = slow = head
          for _ in range(n):
              if not fast.next:
                  raise Exception("less than n nodes found")
              fast = fast.next
          if not fast:
              return head.next
          while fast.next:
              fast = fast.next
              slow = slow.next
          slow.next = slow.next.next
          return head