Share 1-line Python Solution


  • 3
    C
    class Solution(object):
        def addDigits(self, num):
            """
            :type num: int
            :rtype: int
            """
            return num if not num else (num%9 or 9)

  • 0
    M

    Or

    class Solution(object):
        def addDigits(self, num):
            """
            :type num: int
            :rtype: int
            """
            return (num - 1) % 9 + 1 if num else 0
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.