python simple solution,1 line,35ms

  • 0
    class Solution(object):
        def convertToBase7(self, num):
            :type num: int
            :rtype: str
            return ('-' if num<0 else '')+''.join(str(x%7) for x in reversed([abs(num)/(7**i) for i in range(9) if abs(num)/(7**i)>0] if abs(num)>0 else [0]))

Log in to reply

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