class Solution {
public:
string toHex(int num) {
if(num == 0)
return "0";
string ans = "";
unsigned int x = num;
while(x > 0){
int f = x % 16;
if(f < 10) ans = (char)('0'+f)+ans;
else ans = (char)('a'+f-10)+ans;
x /= 16;
}
return ans;
}
};
leetcode 405. Convert a Number to Hexadecimal
最新推荐文章于 2024-08-25 17:36:33 发布