LeetCode ——258.Add Digits
2016-06-29 21:18
369 查看
Given a non-negative integer
one digit.
For example:
Given
only one digit, return it.
C语言解答:
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.
C语言解答:
int addDigits(int num) { int result = num; while(result >= 10) { int temp = 0; while(result / 10 != 0) { temp = temp + result % 10; result = result / 10; } result = result + temp; } return result; }
相关文章推荐
- openstack on centos 7.1(Object Storage)
- NFS安装
- 数据库三范式讲解
- File的sd卡
- DirectXMath
- 【MediaElement】WPF视频播放器【1】
- UVC支持的摄像头列表
- java中的不为空判断
- pull解析请求网络的数据(带分页加载,刷新)
- Codeforces 159D Palindrome pairs
- margin外边距合并详解
- Swift关于NSURL(string:)方法抛出空值错误的问题及解决方案
- best-time-to-buy-and-sell-stock-ii
- C++中的拷贝构造,赋值和移动构造
- iOS App 上架流程-新版本1.0上架
- PHP之图片上传类(加了缩略图)
- Android的activity启动延迟加载
- 测试者的视角
- 读取电话联系人
- 自写信息管理系统——C实现