#405

Convert a Number to Hexadecimal

pupil · 435 · lc easy +25 · verified · 53.4% accepted · 1,438 likes · top 44%

play →

Description

Given a 32-bit signed integer num, return its hexadecimal representation as a lowercase string. Negative values use two's complement, and the result must contain no leading zeros (except for the value 0 itself).

You may not use any built-in hexadecimal conversion function.

Example 1:

Input: num = 26
Output: "1a"

Example 2:

Input: num = -1
Output: "ffffffff"

Code

1
2
3