Leetcode 258 Solution

This article provides solution to leetcode question 258 (add-digits)

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

Solution

class Solution {
public:
    int addDigits(int num) {
        if (num == 0)
            return 0;
        else if (num % 9)
            return num % 9;
        else
            return 9;
    }
};