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

评论

此博客中的热门博文

225 Implement Stack using Queues

232. Implement Queue using Stacks

20. Valid Parentheses