[Leetcode]258. Add Digits
来源:互联网 发布:白光触摸屏 编程软件 编辑:程序博客网 时间:2024/09/21 11:15
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 1+(num-1)%9; }};
0 0
- 【LeetCode】258.Add Digits
- LeetCode 258. Add Digits
- LeetCode : 258. Add Digits
- leetCode 258. Add Digits
- LeetCode 258. Add Digits
- 258. Add Digits LeetCode
- LeetCode 258. Add Digits
- LeetCode 258. Add Digits
- leetcode 258. Add Digits
- [LeetCode]258. Add Digits
- LeetCode 258. Add Digits
- <LeetCode>258. Add Digits
- leetcode--258. Add Digits
- LeetCode 258. Add Digits
- LeetCode *** 258. Add Digits
- Leetcode 258. Add Digits
- 258.[LeetCode]Add Digits
- 【leetcode】258. Add Digits
- 北航2016集训队选拔赛解题报告
- mysql一些使用技巧
- 语义和语法结构之间的关系
- 关于浏览器的问题
- javaType字符数组与jdbcType字符串转换(mybatis)
- [Leetcode]258. Add Digits
- linux select与poll的区别
- Libgdx之Group
- 从头认识多线程-3.2 使用volatile声明的变量的写操作是非原子性的
- 日常生活
- TrueCrypt 变废为宝-银行U盾
- maven
- Bitset类总结
- Arrays类的copyOf与System类的arrayscopy()的区别