Skip to content

Instantly share code, notes, and snippets.

@a7me63azzab
Created June 8, 2020 04:07
Show Gist options
  • Save a7me63azzab/16bfe0f950cf6adabbeed96fb52364de to your computer and use it in GitHub Desktop.
Save a7me63azzab/16bfe0f950cf6adabbeed96fb52364de to your computer and use it in GitHub Desktop.
Problem Solving in Golang
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