--- tags: Leetcode topic: 7. Reverse Integer --- # 7. Reverse Integer ## Solution 直覺寫法 ```c= #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; } ``` 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up