国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LeetCode-AddDigits

2019-11-14 14:53:59
字體:
來源:轉載
供稿:網友

題目:

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.

思路:

除和余

package others;public class AddDigits {    public int addDigits(int num) {        if (num / 10 == 0) return num;        int res = 0;        while (num > 0) {            res += num % 10;            num = num / 10;        }        return addDigits(res);    }        public static void main(String[] args) {        // TODO Auto-generated method stub    }}

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 交口县| 黔西县| 南乐县| 汝城县| 会东县| 沭阳县| 左权县| 綦江县| 阳高县| 金阳县| 西城区| 公安县| 玉林市| 马尔康县| 昌江| 康保县| 兴国县| 潢川县| 湘阴县| 南汇区| 天台县| 本溪| 阳春市| 枞阳县| 台湾省| 彭阳县| 常宁市| 融水| 宜兴市| 许昌县| 珠海市| 塔河县| 桃源县| 从江县| 康定县| 资源县| 探索| 昭通市| 社会| 博爱县| 常熟市|