Easy 5 Lines Python AC Solution


  • 2
    class Solution(object):
        def toHex(self, num):
            
            if num == 0: return "0"
            elif num < 0: num += 2 ** 32
            converthex, res = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"], ""
            while num: num, res = num//16, converthex[num%16]+res
            return res
    

Log in to reply
 

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