Add Digits
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.
代码:
public class Solution {
public int addDigits(int num) {
return 1+(num-1)%9;
}
}
Add Digits的更多相关文章
- 【LeetCode】Add Digits
Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only ...
- Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference
最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...
- 【LeetCode】258. Add Digits (2 solutions)
Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has only ...
- [LeetCode] Add Digits (a New question added)
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
- 258. Add Digits(C++)
258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the result has ...
- LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree
258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...
- 【02_258】Add Digits
Add Digits Total Accepted: 49702 Total Submissions: 104483 Difficulty: Easy Given a non-negative int ...
- LeetCode:Add Digits - 非负整数各位相加
1.题目名称 Add Digits (非负整数各位相加) 2.题目地址 https://leetcode.com/problems/add-digits/ 3.题目内容 英文:Given a non- ...
- LN : leetcode 258 Add Digits
lc 258 Add Digits lc 258 Add Digits Given a non-negative integer num, repeatedly add all its digits ...
- LeetCode_258. Add Digits
258. Add Digits Easy Given a non-negative integer num, repeatedly add all its digits until the resul ...
随机推荐
- HDU 1671 Phone List(Trie的应用与内存释放)
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU 1698 Just a Hook(线段树区间替换)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 字体 font typograph
https://en.wikipedia.org/wiki/Typeface *** 字体渲染 https://www.smashingmagazine.com/2012/04/a-closer-lo ...
- php调用empty出现错误Can't use function return value in write context
php调用empty出现错误Can't use function return value in write context 2012-10-28 09:33:22 | 11391次阅读 | 评论:0 ...
- rsync安装及配置
一.Server端 CentOS 6下安装yum -y install xinetd1.配置:vi /etc/xinetd.d/rsyncservice rsync{ disable = yes ...
- 初步理解Java的三大特性——封装、继承和多态
声明:整理自网络,如有雷同,请联系博主处理 一.封装 封装从字面上来理解就是包装的意思,专业点就是信息隐藏,是指利用抽象数据类型将数据和基于数据的操作封装在一起,使其构成一个不可分割的独立实体,数据被 ...
- overloading
Computer Science An Overview _J. Glenn Brookshear _11th Edition_C Many programming languages allow t ...
- 【转】Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authenticat
Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authenticat 当m ...
- 【nodejs】使用Node.js实现REST Client调用REST API
最近在产品中开发基于REST的API接口,结合自己最近对Node.js的研究,想基于它开发一个REST Client做测试之用. 通过初步研究,Node.js开发HTTP Client还是挺方便的. ...
- Java高级之线程同步
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 关于实现多线程的意义,"从业四年看并发"一文已经讲述,而本篇主要讲一下常用的设计 ...