258. Add Digits¶ Time: $O(1)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6class Solution { public: int addDigits(int num) { return 1 + (num - 1) % 9; } }; 1 2 3 4 5class Solution { public int addDigits(int num) { return 1 + (num - 1) % 9; } } 1 2 3class Solution: def addDigits(self, num: int) -> int: return 0 if num == 0 else 1 + (num - 1) % 9