t = _add(l3.val + t) l3 = l3.next if (t > 0): temp = ListNode(t) current.next = temp current = temp return dummyHead.next if __name__ == '__main__': # l1 = ListNode.array2ist([9,9,9,9,9,9]) # l2 = ListNode.array2ist([9,9,9,9]) # l1 = ListNode.array2ist([2,4,9]) # l2 = ListNode.array2ist([5,6,4,9]) l1 = ListNode.array2ist([9, 9, 1]) l2 = ListNode.array2ist([1]) print("------------------l1------------------") ListNode.show(l1) print("------------------l2------------------") ListNode.show(l2) solution = Solution() result = solution.addTwoNumbers(l1, l2) # result = solution.addTwoNumbersRecursive(l1, l2) print("----------------result----------------") ListNode.show(result)
pos = _getLength(head) - n if (pos < 0): return head prev = current = head i = 0 while (current): if (i == pos): if (i == 0): head = head.next break prev.next = current.next break prev, current, i = current, current.next, i + 1 return head if __name__ == '__main__': list = ListNode.array2ist([5,6,4,9]) # list = ListNode.array2ist([1]) solution = Solution() result = solution.removeNthFromEnd(list, 4) ListNode.show(result)