题意:给出一个数,求将其各位数相加起来后的和,直到小于10

思路:参考https://en.wikipedia.org/wiki/Digital_root

代码如下:

public class Solution
{public int addDigits(int num){if (0 == num) return 0;else if (num % 9 == 0) return 9;else return num % 9;}
}

LeetCode Add Digits(计算数位的和)相关推荐

  1. leetcode Add Digits

    题目连接 https://leetcode.com/problems/add-digits/ Add Digits Description Given a non-negative integer n ...

  2. [LeetCode] Add Digits

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  3. [LeetCode] Add Digits - 数字各个位数求和

    题目概述: Given a non-negative integer num, repeatedly add all its digits until the result has only one ...

  4. Leetcode刷题记录[python]——258 Add Digits

    一.前言 做这题有个小收获,关于Digital root的解法,有个极方便的小公式: 二.题258 Add Digits Given a non-negative integer num, repea ...

  5. LeetCode Add Two Numbers II(栈)

    问题:给出两个链表表示的整数,求其和 思路:因为链表的第一个结点是最高位,最后一个结点是最低位.先将两个链表放入两个栈中.然后从两个栈中取出元素,从低到高位相加. 具体代码参考: https://gi ...

  6. LeetCode Add and Search Word - Data structure design(字典树)

    问题:设计一个支持addWord,search查询的数据结构,要求search支持.正则查询 思路:使用Trie数据结构,在匹配.时,从子结点中选取可行的一个继续匹配下一个字符,主要思路是基于递归 具 ...

  7. [leetcode][math] Add Digits

    题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one di ...

  8. LeetCode之Add Digits

    1.题目 Given a non-negative integer num, repeatedly add all its digits until the result has only one d ...

  9. [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数

    Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...

最新文章

  1. oracle修改c root,从新发现Oracle太美之root.sh
  2. 如何解决经常出现Windows数据执行保护的提示?
  3. Java的calendar类用法
  4. ubuntu 16.04 源码安装samba并且配置
  5. T-SQL: Batches
  6. 2021-2025年中国顶级服务行业市场供需与战略研究报告
  7. 《C++ Primer》第五版课后习题解答_第六章(1)(01-07)
  8. locat add filter
  9. 使用 jQuery 修改 css 中带有 !important 的样式属性
  10. Asp.net core WebApi 使用Swagger生成帮助页实例
  11. Ubuntu 命令技巧
  12. iOS开发全套资源,从入门到全栈IOS工程师
  13. 修改Windows7启动画面与登录画面
  14. Android app 启动优化
  15. Office2013 Visio2013 Project2013零售版与VL版互相转换
  16. 单片机学习笔记————51单片机实现两片联级74HC595驱动16个LED灯(把74HC595驱动程序翻译成类似单片机IO口直接驱动的方式)
  17. MYSQL 查询某个月有多少天数?
  18. 宽高不定div水平、垂直居中
  19. rm -rf和rm -f和rm
  20. 一起talk C栗子吧(第一百九十三回:C语言实例--DIY less命令二 )

热门文章

  1. 简单的表单提交 by MVC 2
  2. 细数Ajax Control Toolkit 34个服务器端控件
  3. python下载文件到指定文件夹-python实现指定文件夹下的指定文件移动到指定位置...
  4. python常用模块大全总结-python常用模块整理
  5. python界面图片-python图形用户界面(六):可视化给图片添加上文字
  6. python代码示例图形-Python使用matplotlib绘制3D图形(代码示例)
  7. python读取excel表格-python怎么读取excel表格
  8. python基础教程教材-Python3零基础教材电子书合集
  9. python读音有道词典-有道词典命令行快速翻译,Python编程的利器
  10. python脚本实例手机端-手机APP自动签到-python实现 - 运维之路