long int res=0;
res = res*10+x%10;
x = x/10;
strange. this can't be right. it already overflowed by the time it was tested.
UPDATE: sorry, you were right. realized you used long int.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.