描述
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.
分析
找数学规律的一道题,比方说38,是3+8,而前面的3是30%9得到的,而11,1+1,前面的1是10%9得到的,
解决方案1(C++)
1 | class Solution { |