Created
November 12, 2017 13:39
-
-
Save volkanbicer/51766598568d260b63602f5be23d0035 to your computer and use it in GitHub Desktop.
Rever 32 bit signed integer. Return 0 if reversed overlfows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func reverse(_ x: Int) -> Int { | |
| var r = 0 | |
| var y = x | |
| while y != 0 { | |
| r = r*10 + y%10 | |
| y = y/10 | |
| } | |
| if r < Int32.min || r > Int32.max { | |
| return 0 | |
| } | |
| return r | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment