258. Add Digits
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 68% Topics: Math, Simulation, Number Theory
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(1)
# Space: O(1)
class Solution(object):
"""
:type num: int
:rtype: int
"""
def addDigits(self, num):
return (num - 1) % 9 + 1 if num > 0 else 0
Solution from kamyu104/LeetCode-Solutions · MIT