258. Add Digits
来源:互联网 发布:淘宝便利店 编辑:程序博客网 时间:2024/05/22 05:24
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?
代码:
class Solution {
public int addDigits(int num) {
return num==0?0:(num-1)%9+1;
}
}
阅读全文
0 0
- 258.Add Digits
- 【LeetCode】258.Add Digits
- 258. Add Digits
- LeetCode 258. Add Digits
- 258. Add Digits
- LeetCode : 258. Add Digits
- 258. Add Digits
- 258. Add Digits
- 258. Add Digits
- 258. Add Digits
- 258. Add Digits
- leetCode 258. Add Digits
- LeetCode 258. Add Digits
- 258. Add Digits LeetCode
- 258. Add Digits
- 258. Add Digits
- LeetCode 258. Add Digits
- 258. Add Digits
- java类成员初始化顺序以及四种代码块
- 竞彩推送---人工智能竞彩稳胆稳单推送(快来群里看看)
- HeadFirst设计模式读书笔记
- 设置精灵
- eclipse 配置 Maven
- 258. Add Digits
- mtk otg代码阅读笔记
- 通过先序遍历和中序遍历建立二叉树
- 73. Set Matrix Zeroes
- c++基础之类的封装
- python numpy中数组.min()
- SpringMVC学习之简单示例(非注解)
- Python之正则表达式入门
- sleep和wait的区别