Skip to content

Instantly share code, notes, and snippets.

@volkanbicer
Created November 12, 2017 13:39
Show Gist options
  • Select an option

  • Save volkanbicer/51766598568d260b63602f5be23d0035 to your computer and use it in GitHub Desktop.

Select an option

Save volkanbicer/51766598568d260b63602f5be23d0035 to your computer and use it in GitHub Desktop.
Rever 32 bit signed integer. Return 0 if reversed overlfows
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