Created
August 26, 2020 07:12
-
-
Save foreversmart/2360475d21f7ccb3d286862e5a99e5c0 to your computer and use it in GitHub Desktop.
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
// 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