LeetCode
来源:互联网 发布:js控制div旋转 编辑:程序博客网 时间:2024/06/18 15:29
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?
嗯,找规律吧0 0
发现数字从小到大,答案1~9循环
class Solution {public: int addDigits(int num) { return 1 + (num - 1) % 9; }};
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- 序列化
- equals()方法和"=="区别
- 聚焦合伙人大会(四):一场为艺术而献身的慈善晚宴
- 【TensorFlow入门】安装路径问题
- java.lang.NoClassDefFoundError: okhttp3.MediaType
- LeetCode
- STL string
- SBT 配置依赖打包
- 将xml文件格式的excel并和的工具类
- 什么是信号完整性?(于博士信号完整性)
- UVA
- java.util.logging.logger的使用
- C++Builder PID控制一阶惯性系统
- UVA