Convert a Number to Hexadecimal Solutions in C++Number 405Difficulty EasyAcceptance 43.9%Link LeetCodeOther languages GoSolutionsC++ solution by haoel/leetcode// Source : https://leetcode.com/problems/convert-a-number-to-hexadecimal/// Author : Hao Chen// Date : 2016-11-12 class Solution {public: string toHex(int num) { if (num == 0) return "0"; unsigned int x = num; string result; for(;x > 0; x/=16) { int n = x % 16; char c; if (n < 10) c = n + '0'; else c = 'a' + n - 10 ; result = c + result; } return result; }};// Source : https://leetcode.com/problems/convert-a-number-to-hexadecimal/ // Author : Hao Chen // Date : 2016-11-12 class Solution { public: string toHex(int num) { if (num == 0) return "0"; unsigned int x = num; string result; for(;x > 0; x/=16) { int n = x % 16; char c; if (n < 10) c = n + '0'; else c = 'a' + n - 10 ; result = c + result; } return result; } };