Try   HackMD

7. Reverse Integer

Solution 直覺寫法

#define MAX_INT (int)((unsigned)(-1)>>1) #define MIN_INT (int)(~MAX_INT) int reverse(int x){ if(x>=MAX_INT||x<=MIN_INT) return 0; int pos = (x>>31); int ans =0; x =pos?x*(-1):x; while(x>9){ ans = ans*10 + x%10; x=x/10; } if(ans>(MAX_INT/10)) return 0; ans = ans*10 + x%10; ans = pos?ans*(-1):ans; return ans; }

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →