LeetCode 405 Convert a Number to Hexadecimal
来源:互联网 发布:小语网络加速器 编辑:程序博客网 时间:2024/06/04 20:08
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.
Note:
- All letters in hexadecimal (
a-f
) must be in lowercase. - The hexadecimal string must not contain extra leading
0
s. If the number is zero, it is represented by a single zero character'0'
; otherwise, the first character in the hexadecimal string will not be the zero character. - The given number is guaranteed to fit within the range of a 32-bit signed integer.
- You must not use any method provided by the library which converts/formats the number to hex directly.
Example 1:
Input:26Output:"1a"
Example 2:
Input:-1Output:"ffffffff"
Runtime: 7 ms
static char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};public String toHex(int num) {return num >>> 4 == 0 ? String.valueOf(digits[num & 0xf]) : toHex(num >>> 4) + digits[num & 0xf];}
public String toHex2(int num) {String hexs = new String();while (num != 0) {hexs = digits[num & 0xf] + hexs;num = num >>> 4;}return hexs.length() == 0 ? "0" : hexs;}
0 0
- LeetCode 405 Convert a Number to Hexadecimal
- LeetCode[405] Convert a Number to Hexadecimal
- LeetCode #405: Convert a Number to Hexadecimal
- Leetcode 405 Convert a Number to Hexadecimal
- Leetcode Convert a Number to Hexadecimal 405
- Leetcode 405: Convert a Number to Hexadecimal
- LeetCode 405 Convert a Number to Hexadecimal
- [Leetcode] Convert a Number to Hexadecimal
- [LeetCode]Convert a Number to Hexadecimal(Java)
- LeetCode 405. Convert a Number to Hexadecimal
- [LeetCode]--405. Convert a Number to Hexadecimal
- [leetcode]405. Convert a Number to Hexadecimal
- LeetCode 405. Convert a Number to Hexadecimal
- leetcode 405. Convert a Number to Hexadecimal
- leetcode 405. Convert a Number to Hexadecimal
- LeetCode 405. Convert a Number to Hexadecimal
- LeetCode 405. Convert a Number to Hexadecimal
- 【LeetCode】 405. Convert a Number to Hexadecimal
- 一天一篇批处理之——Part3:复制/移动文件命令move,copy,xcopy
- HTML5之WebSoket——html5+java servlet实现
- phpstorm激活方法
- 【codeforces 721C】【DAG 按照拓扑排序记忆化DFS】C. Journey 【DAG图,5000个点,5000条边 让你求从1到n的路径长度不超过T中经过点数最多的一条 】
- HDU 5833 Zhu and 772002(异或方程组高斯消元)
- LeetCode 405 Convert a Number to Hexadecimal
- 适配器模式
- (Java)LeetCode-50. Pow(x, n)
- Python:class类
- forward和param动作
- linux 终端命令大全
- 动态链接库的使用
- cglib代理
- C++/STL bitset