leetcode258

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

原文地址:https://www.cnblogs.com/asenyang/p/6732302.html