一看不让用循环就有点蒙。 只能找规律。和9相关。 class Solution { public: int addDigits(int num) { if(num==0) return 0; if(num%9==0) return 9; return num%9; } } };
原创 2022-08-05 15:58:46
47阅读
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example: Follow up:Could you do it without any lo
转载 2019-10-28 09:19:00
68阅读
2评论
Given a non negative integer num, repeatedly add all its digits until the result has only one digit. Example: Input: 38 Output: 2 Explanation: The pro
转载 2018-10-05 11:11:00
120阅读
2评论
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For exam
原创 2022-08-03 16:56:37
41阅读
题目: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
原创 2023-03-07 12:33:50
21阅读
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. + 8 = 11, 1 + 1 = 2. Since 2 has on
git
原创 2023-09-05 09:28:23
12阅读
题目 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example: Input: 38 Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2.
git
原创 2024-06-17 09:10:18
31阅读
int addDigits(int num){ while(num>=10){ int temp=0; while(num){ temp += num%10; num/=10; } num=temp; } return num; }
转载 2020-12-02 15:16:00
91阅读
2评论
【题目描述】给定一个非负整数 ​​num​​,反复将各个位上的数字相加,直到结果为一位数。返回这个结果。​​https://leetcode.cn/problems/add-digits/description/​​【示例】【代码】​​Storm​​思路: num % 10  --> 求个位数          &nbsp
原创 2023-01-07 20:36:39
85阅读
https://leetcode-cn.com/problems/add-digits/class Solution { public int addDig
原创 2022-08-19 15:38:57
35阅读
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the 2 has only one digit, r
原创 2023-06-07 15:50:09
53阅读
public int addDigits(int num) {if (num < 10) {return num;}int next = 0;while (num != 0) {next = next + num % 10;num /= 10;}return addDigits(next);}上边的递归很简单可以直接写成迭代的形式。public int addDigits(int num) {while (num >= 10) {int next = 0;while
原创 2023-05-15 16:43:50
110阅读
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. Example: Input: 38 Output: 2 Explanation: The pro
转载 2019-10-17 23:58:00
74阅读
2评论
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:
转载 2016-08-31 21:48:00
47阅读
2评论
给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。 示例: 输入: 38输出: 2 解释: 各位相加的过程为:3 + 8 = 11, 1 + 1 = 2。 由于 2 是一位数,所以返回 2。进阶:你可以不使用循环或者递归,且在 O(1) 时间复杂度内解决这个问题吗? class
转载 2020-09-29 19:01:00
73阅读
2评论
"题目" 同余定理,任何一个10进制数n 都可以表示成 n = a 10^x + b 10^(x 1) + .... c 10^0 那么 n ≡ ( a 10^x + b 10^(x 1) + .... c 10) mod 9 ( a 10^x + b 10^(x 1) + .... c 10) m
原创 2022-10-18 13:59:12
52阅读
problem 258. Add Digits solution1: solution2: Digital_root 参考 1. Leetcode_258. Add Digits; 2. Digital_root; 完
git
原创 2022-07-10 00:28:58
50阅读
DescriptionGiven a non-negative integer num, repeate
原创 2022-08-11 21:54:49
21阅读
给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数。
原创 2022-12-07 14:11:08
79阅读
算法标签题目简叙思路代码class Solution {public: int addDigits(int nu
git
原创 2023-03-20 14:59:13
95阅读
  • 1
  • 2
  • 3
  • 4
  • 5