class Solution:
def addDigits(self, num: int) -> int:
if num==0:
return 0
elif num%9==0:
return 9
else:
return num%9
#----------------------------------------
class Solution:
def addDigits(self, num: int) -> int:
if num==0:
return 0
return 1+(num-1)%9
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter