258. Add Digits
2016-05-13 17:45
316 查看
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.
Answer with Python:
Answer with C:
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.
Answer with Python:
class Solution(object): def addDigits(self, num): if num==0: return 0 else: return 1+(num -1)%9
Answer with C:
int addDigits(int num) { return 1 + (num-1) % 9; }
相关文章推荐
- 1》找到接口-浏览器-收集接口
- Swift UITableView 的简单使用
- 设计模式(Design Patterns)
- UVA 11437 Triangle Fun 几何基础
- 坚持 幻方 ?
- Day 1 :成功完成注册
- spring-mvc junit测试
- 玩转Android studio 插件开发、测试、JCenter库发布(1)
- Linux常用命令汇总--rmdir
- 轻松制作GIF动画!教你玩转PS时间轴之5个小技巧篇
- 让VS编译的Release版本程序在其他机器上顺利运行
- activiti 5.19整合modeler在线编辑器
- POJ_2001_Shortest_Prefixes_(Trie)
- xml中空格换行缩进
- How do I write things in Swift?
- 物流接口查询
- Hbase原理、基本概念、基本架构
- 【详细图解】一步一步教你自定义博客园(cnblog)界面
- 对于Picasso的封装和优化方案
- isEqual