Algorithm Puzzles: Add Digits
Algorithm Puzzles everyday every week sometimes: Add Digits
Puzzle
Puzzle from leetcode:
Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.
Example 1:
1 | Input: num = 38 |
Solution
There is a math pattern in this puzzle:
1 | class Solution { |
T.C.: O(1)
S.C.: O(1)