Given a non-negative integer For example: Given Follow up: Could you do it without any loop/recursion in O(1) runtime? 有关Digital_Root,大概就是求一个数的各个位之和,若这个数为个位数,则它即原数的DigitalRoot,若不是,则再对它进行数位求和。这个在网上看到有个公式是F(N)=(N-1)%9+1; Solution: 1. 逐位相加直到小于10 2. 通过输入距离来发现规律 123456789 10 11 12 13 14 15 123456789 1 2 3 4 5 6 |
|
来自: 雪柳花明 > 《LeetCode》