I used python for solving. This is my implementation -
class Solution(object): def reverse(self, x): if x>0: return int(''.join(list(reversed(str(x))))) elif x<0: return int('-'+''.join(list(reversed(str(x*(-1)))))) else: return 0
When I run this on leetcode I get wrong answer for the following test case -
But when I run it using Pycharm on my local machine, it gives me the output which I am getting when run on leetcode i.e. 9646324351. So shouldn't that be the expected answer?
I understand the problem asks me to return 0 if overflow occurs, but in case of python, overflow does not occur - the variable automatically resizes itself. But still 0 is the expected answer. Why?