Add Digits
Problem: Add Digits
The answer will only be 1,2,3,4,5,6,7,8,9 except 0 for 0. And the answer iterate by nine.
Code in Python:
class Solution(object):
def addDigits(self, num):
"""
:type num: int
:rtype: int
"""
if num == 0: return 0
ans = [9, 1, 2, 3, 4, 5, 6, 7, 8]
return ans[num % 9]