1271. Hexspeak

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1271

class Solution:
    def toHexspeak(self, num: str) -> str:
        s = set('ABCDEFIO')
        t = hex(int(num))[2:].upper().replace('0', 'O').replace('1', 'I')
        return t if all(c in s for c in t) else 'ERROR'