Created
June 8, 2020 04:07
-
-
Save a7me63azzab/16bfe0f950cf6adabbeed96fb52364de to your computer and use it in GitHub Desktop.
Problem Solving in Golang
This file contains 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 { | |
rev:= 0 | |
for x != 0 { | |
pop := x % 10 | |
x = x / 10 | |
if rev > math.MaxInt32/10 || (rev == math.MaxInt32 /10 && pop > 7) { | |
return 0 | |
} | |
if rev < math.MinInt32/10 || (rev == math.MinInt32/10 && pop < -8) { | |
return 0 | |
} | |
rev = rev * 10 + pop | |
} | |
return rev | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment