C++ solution with one line


  • 1
    A
    class Solution {
    public:
        int addDigits(int num) {
            return num != 0 ? (num % 9 == 0 ? 9 : num % 9) : 0;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.