share my 7ms java solution


  • 0
    C
    public String toHex(int num) {
        char[] ret = new char[8];
        int mask = 0x0000000f, index = 7;
        for(int i = 0; i < 8 && !(i != 0 && num == 0); i++){
        	int code = num & mask;
            ret[index--] = (char) ((code > 9? 'a' - 10: '0') + code) ;
            num >>>= 4;
        }
        return new String(ret, index + 1, 7 - index);
    }

Log in to reply
 

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