258. Add Digits
class Solution(object):
def addDigits(self, num):
"""
:type num: int
:rtype: int
"""
if num==0:
return 0
a=num%9
return a if a !=0 else 9
找规律题……醉了
class Solution(object): def addDigits(self, num): """ :type num: int :rtype: int """ res = num % 9 return res if (res != 0 or num == 0) else 9
def addDigits(self, num):
"""
:type num: int
:rtype: int
"""
if num==0:
return 0
a=num%9
return a if a !=0 else 9
找规律题……醉了
class Solution(object): def addDigits(self, num): """ :type num: int :rtype: int """ res = num % 9 return res if (res != 0 or num == 0) else 9
评论
发表评论