LeetCode solutions

3912. Hexadecimal and Hexatrigesimal Conversion

My accepted Python solution to LeetCode problem 3912, Hexadecimal and Hexatrigesimal Conversion, running in 1ms.

  • Difficulty: Easy
  • Python
  • Runtime 1ms
  • Memory 17.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 1ms, memory 17.4MB, accepted 2025-12-31.

python
class Solution:
    def concatHex36(self, n: int) -> str:
        def to_base(num, base):
            if num == 0:
                return '0'
            digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
            result = ''
            while num:
                result = digits[num % base] + result
                num //= base
            return result
        
        hex_val = to_base(n * n, 16)
        hex36_val = to_base(n * n * n, 36)
        return hex_val + hex36_val

Source