Math Fundamentals18 sections · 814 units
Open in Course

Add Digits - Algorithm

(O(1) formula)

1.1. If num = 0, return 0.

2.2. Otherwise return 1 + (num - 1) % 9.

This runs in constant time and uses the modular property.