Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
这道题,如果从1开始一个个数,就知道规律了,然后你要注意能被9整除的情况以及0的情况
class Solution(object):
def addDigits(self, num):
"""
:type num: int
:rtype: int
"""
return 0 if num==0 else 1+(num-1)%9