class Solution(object): def toHex(self, num): return hex(num)[2:] if num >= 0 else hex(0xffffffff+num+1)[2:]
This goes against the spirit of the question -- you're using built-in function
Though I guess you could be a smartass and claim that it doesn't contradict
4. You must not use any method provided by the library which converts/formats the number to hex directly. because it's not part of a library...
@Fry-kun Oh, I didn't consider that condition. Thank you for letting me know:)
it's not part of a library
It's part of Python's standard library.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.