Skip to content

Commit 2157fc4

Browse files
authored
Update hexspeak.py
1 parent 5ca7673 commit 2157fc4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Python/hexspeak.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,15 @@ def toHexspeak(self, num):
1818
return "ERROR"
1919
result.append(lookup[r])
2020
return "".join(reversed(result))
21+
22+
23+
# Time: O(n)
24+
# Space: O(n)
25+
class Solution2(object):
26+
def toHexspeak(self, num):
27+
"""
28+
:type num: str
29+
:rtype: str
30+
"""
31+
result = hex(int(num)).upper()[2:].replace('0', 'O').replace('1', 'I')
32+
return result if all(c in "ABCDEFOI" for c in result) else "ERROR"

0 commit comments

Comments
 (0)