public class Solution {
public int AddDigits(int num) {
var str = num.ToString(); int result = ; foreach (var c in str)
{
result += Convert.ToInt32(c.ToString());
} if (result >= )
{
result = AddDigits(result);
} return result;
}
}

https://leetcode.com/problems/add-digits/#/description

leetcode258的更多相关文章

  1. LeetCode258:Add Digits

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

  2. [LeetCode258] Add Digits 非负整数各位相加

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

  3. [Swift]LeetCode258. 各位相加 | Add Digits

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

  4. LeetCode258 各位相加

    题目链接:https://leetcode-cn.com/problems/add-digits/ 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数. 示例: 输入: 38 输出: ...

  5. LeetCode258——Add Digits

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

  6. LeetCode172 Factorial Trailing Zeroes. LeetCode258 Add Digits. LeetCode268 Missing Number

    数学题 172. Factorial Trailing Zeroes Given an integer n, return the number of trailing zeroes in n!. N ...

  7. LeetCode 258

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

  8. k进制正整数的对k-1取余与按位取余

    华电北风吹 天津大学认知计算与应用重点实验室 日期:2015/8/24 先说一下结论 有k进制数abcd,有abcd%(k−1)=(a+b+c+d)%(k−1) 这是由于kn=((k−1)+1)n=∑ ...

  9. LeetCode 258. 各位相加(Add Digits)

    258. 各位相加 258. Add Digits 题目描述 给定一个非负整数 num,反复将各个位上的数字相加,直到结果为一位数. LeetCode258. Add Digits 示例: 输入: 3 ...

随机推荐

  1. poj1797 最短路

    虽然不是求最短路,但是仍然是最短路题目,题意是要求1到N点的一条路径,由于每一段路都是双向的并且有承受能力,求一条路最小承受能力最大,其实就是之前POJ2253的翻版,一个求最大值最小,一个求最小值最 ...

  2. jsp页面九大内置对象

    资源转载自网上,不可用于商用,学习可以.内置对象又叫隐式对象/隐含对象是由WEB容器加载的一组类的实例,不需要预先声明就可以在脚本代码和表达式中随意使用的对象. 这九大隐式对象可以按照期作用分类为: ...

  3. python 取整

    1.向下取整 向下取整直接用内建的 int() 函数即可: >>> a = 3.75 >>> int(a) 3 2.四舍五入 对数字进行四舍五入用 round()  ...

  4. dbt 基本试用

    dbt 是一个很不错的进行etl 中的t 处理的工具,灵活简单,我们需要写的就是select 语句 dbt 帮助我们进行处理 测试集成了graphql 以及使用docker 运行 安装 pip ins ...

  5. oracle 拆分字符串并转换为表

    使用函数的方式 1. 创建的函数以及类型如下: CREATE OR REPLACE TYPE str_split IS TABLE OF VARCHAR2 (4000);CREATE OR REPLA ...

  6. pthread中errors.h的代码

    #ifndef __errors_h #define __errors_h #include <unistd.h> #include <errno.h> #include &l ...

  7. linux同一客户端多个git账号的配置

    有时候我们需要在同一台机器上使用多个git账号,为了避免冲突,我们需要配置~/.ssh/config文件. 步骤一:用ssh-keygen命令生成一组新的id_rsa_new和id_rsa_new.p ...

  8. golang fmt用法举例

    下标与参数的对应 例子如下: package main import ( "fmt" ) func main() { num := 10 fmt.Printf("num: ...

  9. Debug---Eclipse断点调试基础

    1.进入debug模式(基础知识列表)1.设置断点 2.启动servers端的debug模式 3.运行程序,在后台遇到断点时,进入debug调试状态 ========================= ...

  10. java 静态导入