【LeetCode】258.Add Digits
来源:互联网 发布:linux中oracle启动监听 编辑:程序博客网 时间:2024/05/17 01:36
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?
public class Solution { public int addDigits(int num) { if(num == 0){ return 0; } int result = num % 9; return result == 0 ? 9 : result; }}
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
- spring annotation注解
- 013 menu控件使用
- Linux命令收集
- json语法
- Gamma压缩与解压
- 【LeetCode】258.Add Digits
- Windows下安装设置Atlassian-Confluence-5.1.4并破解汉化(另附图解)
- 【Codeforces Beta Round 2A】【模拟 map 有map的java实现哦】Winner 第一个达到最终最高分的人名
- 我的JavaScript设计模式
- Java流 学习笔记
- kdiff3工具
- 编译和运行
- 说说 Wine + QQ 轻聊版 7.7 的安装步骤
- 深入理解Linux修改hostname