leetcode 258: Add Digits
2015-08-19 20:16
323 查看
Add Digits
Total Accepted: 5383Total Submissions: 11876
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
2has only one digit, return it.
Follow up:
Could you do it without any loop/recursion in O(1) runtime?
[思路]
[CODE]
public class Solution { public int addDigits(int num) { return 1 + (num-1) % 9; } }
相关文章推荐
- Android内存分析工具(三):MAT
- Android 笔记2
- 手游服务器之数据IO进化
- Minimum Inversion Number 数状数组
- ios 延迟调用 && UIImageView && UILabel && UISegmentedControl && UISwitch && UISlider
- 儒家经典故事 第二章 潜心修德,正身成事
- 乐透号码
- HDU 3336 Count the string(KMP+Next数组递推)
- HDU - 4090(暴力剪纸题目,)
- IOS-笔记9(多MVC,View间转换)
- flowplayer(5.5.2版本)的播放视频
- 逆序数的几种求法
- 杭电(hdu)2544 最短路
- MLC模式这边看过来
- ios文件管理
- 软件工程—总结
- 123
- vijos - P1739计算系数 (多项式计算 + 杨辉三角形 + 快速幂)
- leetcode 257: Binary Tree Paths
- java IO流总结