首页 > 其他 > 详细

LeetCode: Add Digits

时间:2015-09-28 16:03:40      阅读:171      评论:0      收藏:0      [点我收藏+]

Java:递归调用就行

 1 public class Solution {
 2     public int addDigits(int num) {
 3         if (num < 10) 
 4         {
 5             return num;
 6         }
 7         int ans = 0;
 8         while (num > 0)
 9         {
10             ans += num % 10;
11             num /= 10;
12         }
13         return addDigits(ans);
14     }
15 }

 

LeetCode: Add Digits

原文:http://www.cnblogs.com/yingzhongwen/p/4843949.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!