LeetCode 258 -Add Digits ( JAVA )
来源:互联网 发布:破解 经淘宝排查认定 编辑:程序博客网 时间:2024/05/23 00:56
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?
Hint:
- A naive implementation of the above process is trivial. Could you come up with other methods?
- What are all the possible results?
- How do they occur, periodically or randomly?
- You may find this Wikipedia article useful.
public class Solution { public int addDigits(int num) { return (num-1)%9+1; }}
总结:由题目可知,求一个数的数根,有求数根的公式(PS:别问我怎么来的,我也不知道- - .)
0 0
- leetcode 258 Add Digits(java)
- LeetCode 258 Add Digits java
- LeetCode 258 -Add Digits ( JAVA )
- [LeetCode-258]Add Digits(java)
- 【leetcode】Add Digits【java】
- (java) leetcode Add Digits
- leetcode:Add Digits 【Java】
- leetcode 258: Add Digits
- 258Add 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
- SharePoint\O365 "See also"功能 and site feature 激活\禁用小节
- Messenger/Handler and Binder
- JQueryEasyUi学习笔记
- Cordova android框架详解
- Oracle 实例内存结构
- LeetCode 258 -Add Digits ( JAVA )
- python小技巧
- Android进阶——属性动画Property Animation详解(一)
- mac mysql 5.7.11 安装成功之后忘记密码
- 《剑指Offer》学习笔记——从尾到头打印链表
- hibernate @Temporal
- 11gRAC对单机dataguard
- 安卓事件分发机制
- Android使用GridView实现简单的日历