c++


  • 0
    T
    class Solution {
    public:
        string toHex(int num) {
            if (!num) return "0";
            string rst, hex = "0123456789abcdef";
            while (num && rst.size() < 8) {
                rst = hex[num&0xf] + rst;
                num >>= 4;
            }
            return rst;
        }
    };
    

Log in to reply
 

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