Skip to content

Instantly share code, notes, and snippets.

@foreversmart
Created August 26, 2020 07:12
Show Gist options
  • Save foreversmart/2360475d21f7ccb3d286862e5a99e5c0 to your computer and use it in GitHub Desktop.
Save foreversmart/2360475d21f7ccb3d286862e5a99e5c0 to your computer and use it in GitHub Desktop.
golang 字符串翻转
// only support ascii
func reverseString(s string) string {
b := []byte(s)
for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
// switch
b[i], b[j] = b[j], b[i]
}
return string(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment