Created
October 1, 2016 02:36
-
-
Save husobee/efa8fb99cd8c37b13ee40326821832af to your computer and use it in GitHub Desktop.
reverse a string
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
) | |
func reverseStr(s string) string { | |
input := []byte(s) | |
for i := 0; i < len(input)/2; i++ { | |
input[i], input[(len(input)-1)-i] = input[(len(input)-1)-i], input[i] | |
} | |
return string(input) | |
} | |
func main() { | |
fmt.Println(reverseStr("blahes")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sehalb