text: # Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
  
  # Example:
  
  # Input: 38
  # Output: 2 
  # Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. 
  #              Since 2 has only one digit, return it.
  
  
  class Solution(object):
      def addDigits(self, num):
          """
          :type num: int
          :rtype: int
          """
          return 0 if num == 0 else num % 9 or 9
  
  
  # Time: O(1)
  # Space: O(1)
  # Difficulty: easy