Clear python solution


  • 0
    A
    def toHex(self, num):
        quot = 0
        remainder = []
        result = ""
        if num < 0:
            num += 2**32
        elif num == 0:
            return "0"
        while num:
            quot = num / 16
            remainder += [num % 16]
            num = quot
        for i in xrange(len(remainder) - 1, -1 , -1):
            if remainder[i] > 9:
                result += chr(remainder[i] + 87)
            else:
                result += str(remainder[i])
        return result

Log in to reply
 

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