Skip to content

Instantly share code, notes, and snippets.

@hellojukay
Created January 17, 2019 16:10
Show Gist options
  • Save hellojukay/2378b12f673132fc4a199bf151b943ee to your computer and use it in GitHub Desktop.
Save hellojukay/2378b12f673132fc4a199bf151b943ee to your computer and use it in GitHub Desktop.
package main

func reverse(str string) string {
	if len(str) == 0 || str == " " {
		return str
	}
	index := 0
	for index < len(str) && str[index] != ' ' {
		index = index + 1
	}
	if index == len(str) {
		return str
	}
	return reverse(string(str[index+1:])) + " " + string(str[0:index])
}
func main() {
	var str = "jiu shi ni , rang wo da ban ye bu shui jiao , zai zheli zuo timu !"
	println(str)
	println(reverse(str))
}

run it

go run main.go

stdout

jiu shi ni , rang wo da ban ye bu shui jiao , zai zheli zuo timu !
! timu zuo zheli zai , jiao shui bu ye ban da wo rang , ni shi jiu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment