leetcode-Add Digits

来源:互联网 发布:叮叮软件定位查询 编辑:程序博客网 时间:2024/06/06 03:14

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 = 111 + 1 = 2. Since 2 has only one digit, return it.

给一个非负整数,重复执行上面的操作,直到结果为一位数,返回该数。

public class Solution {    public int addDigits(int num) {       return (num-1)%9+1;    }}



0 0
原创粉丝点击