405. Convert a Number to Hexadecimal Easy
1/**
2 * [405] Convert a Number to Hexadecimal
3 *
4 * Given an integer num, return a string representing its hexadecimal representation. For negative integers, <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank">two’s complement</a> method is used.
5 * All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself.
6 * Note: You are not allowed to use any built-in library method to directly solve this problem.
7 *
8 * Example 1:
9 * Input: num = 26
10 * Output: "1a"
11 * Example 2:
12 * Input: num = -1
13 * Output: "ffffffff"
14 *
15 * Constraints:
16 *
17 * -2^31 <= num <= 2^31 - 1
18 *
19 */
20pub struct Solution {}
21
22// problem: https://leetcode.com/problems/convert-a-number-to-hexadecimal/
23// discuss: https://leetcode.com/problems/convert-a-number-to-hexadecimal/discuss/?currentPage=1&orderBy=most_votes&query=
24
25// submission codes start here
26
27impl Solution {
28 pub fn to_hex(num: i32) -> String {
29 String::new()
30 }
31}
32
33// submission codes end
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_405() {
41 }
42}
43
Back
© 2025 bowen.ge All Rights Reserved.