Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

public class Solution { public int addDigits(int num) { return num<10? num: (num%9==0? 9: num%9); } }

genius! The result can only be 0-9. The remainder of the number divided by 9 is exactly the sum of the digits, except when the remainder is 0, the sum should be 9.

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