Skip to content

Instantly share code, notes, and snippets.

@c-yan
Last active February 27, 2018 13:49
Show Gist options
  • Save c-yan/d5ba9d559dfbc36e281a08e62117b07f to your computer and use it in GitHub Desktop.
Save c-yan/d5ba9d559dfbc36e281a08e62117b07f to your computer and use it in GitHub Desktop.
00. 文字列の逆順 文字列"stressed"の文字を逆に(末尾から先頭に向かって)並べた文字列を得よ.
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