Skip to content

total [terminology]

Terminology

Usage

  • Use for an additive numeric accumulator.
  • It represents a running sum rather than a number of items.
  • Prefer a domain-specific name such as profit when it communicates more.
  • Do not use it for multiplicative accumulators, frequencies, or optimum tracking.
while l1 or l2 or carry:
    total = carry
    if l1:
        total += l1.val
        l1 = l1.next
    if l2:
        total += l2.val
        l2 = l2.next
    carry, digit = divmod(total, 10)
    tail.next = ListNode(digit)
    tail = tail.next

See 2. Add Two Numbers.