Skip to content

Instantly share code, notes, and snippets.

@mytholog
Last active September 13, 2017 13:00
Show Gist options
  • Save mytholog/fd10e423dbd44d3047310c792db28cc5 to your computer and use it in GitHub Desktop.
Save mytholog/fd10e423dbd44d3047310c792db28cc5 to your computer and use it in GitHub Desktop.
func reverse(s []int) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}
func reverseString(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return string(r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment