Xiaohe-LeetCode 258 Add Digit

This is not the best one.

public class Solution {
  public int addDigits(int num) {
    if(num<10)
      return num;
    int sum=0;
    while(num>=10)
    {
      sum=sum+num%10;
      num=(num-num%10)/10;
    }
    sum=sum+num;
    if(sum<10)
      return sum;
    else
    return addDigits(sum);
  }
}

posted @ 2015-11-22 10:20  CathyXiaohe  阅读(131)  评论(0编辑  收藏  举报