Python fast solution


  • 0
    B

    '''
    class Solution(object):
    def toHex(self, num):
    """
    :type num: int
    :rtype: str
    """
    if num==0:
    return '0'
    op=''
    if num<0:
    num=num+2**32
    dict={0:'0',1:'1',2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9',10:'a',11:'b',12:'c',13:'d',14:'e',15:'f'}

        while num:
            op=dict[num%16]+op
            num=num//16
        
        return op'''

Log in to reply
 

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