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.
Follow up:
Could you do it without any loop/recursion in O(1) runtime?
本文探讨了一种数字压缩算法,该算法可以将一个非负整数的所有位数加起来,直到结果只有一位数为止。例如,对于数字38,过程为3+8=11, 1+1=2。由于2只有一位数,因此返回2。此外,文章还讨论了如何在O(1)运行时间内不使用任何循环或递归实现这一功能。
2633

被折叠的 条评论
为什么被折叠?



