public class Solution {
    public int AddDigits(int num) {
        var str = num.ToString();

            int result = 0;

            foreach (var c in str)
            {
                result += Convert.ToInt32(c.ToString());
            }

            if (result >= 10)
            {
                result = AddDigits(result);
            }

            return result;
    }
}

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

posted on 2017-04-19 11:03  Sempron2800+  阅读(105)  评论(0编辑  收藏  举报