It's a mathematical error if x=0 and n<0.
My code just return 0 for every x=0 and was accepted
According to 'My code just return 0 for every x=0 and was accepted', I believe you miss the test case x = 0, n = 0, not x=0, n<0.
x = 0, n = 0
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.