Given a non-negative integer
num
, repeatedly add all its digits until the result has only one digit.
Follow up:
Could you do it without any loop/recursion in O(1) runtime?
給一個非負整數
num
,重複地把它所有位數加總,直到結果只剩個位數。
進階題:
你可以不使用任何迴圈/遞迴且在O(1)的時間複雜度完成嗎?
LeetCode
C++