题目
Given a non-negative integer num
, repeatedly add all its digits until the result has only one digit.
Example:
1 | Input: 38 |
Follow up:
Could you do it without any loop/recursion in O(1) runtime?
思路
代码
1 | class Solution(object): |
Given a non-negative integer num
, repeatedly add all its digits until the result has only one digit.
Example:
1 | Input: 38 |
Follow up:
Could you do it without any loop/recursion in O(1) runtime?
1 | class Solution(object): |