Last active
February 27, 2018 13:49
-
-
Save c-yan/d5ba9d559dfbc36e281a08e62117b07f to your computer and use it in GitHub Desktop.
00. 文字列の逆順 文字列"stressed"の文字を逆に(末尾から先頭に向かって)並べた文字列を得よ.
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" | |
"reflect" | |
) | |
func Reverse(slice interface{}) { | |
t := reflect.ValueOf(slice) | |
swap := reflect.Swapper(slice) | |
l := t.Len() | |
for i := 0; i < l/2; i++ { | |
swap(i, l-i-1) | |
} | |
} | |
func main() { | |
result := []byte("stressed") | |
Reverse(result) | |
fmt.Println(string(result)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment