def _sum_normal(first_node, second_node): head, carry = carry_and_sum(first_node, second_node) if carry == 0: return head new_head = SingleLinkNode(carry) new_head.next = head return new_head
def linked_number_reverse(num): if num < 0: return None if num < 10: return SingleLinkNode(num) head = SingleLinkNode(num % 10) head.next = linked_number_reverse(num / 10) return head
def _sum_reverse(first_node, second_node, carry): if first_node is None and second_node is None: if carry == 1: return SingleLinkNode(carry) else: return None addition = carry if first_node is not None: addition += first_node.val if second_node is not None: addition += second_node.val current = SingleLinkNode(addition % 10) current.next = _sum_reverse(first_node.next, second_node.next, addition / 10) return current
def complete_with_zeros(number_node, zeros): if zeros <= 0: return number_node head = SingleLinkNode(0) head.append(complete_with_zeros(number_node, zeros - 1)) return head