Skip to content

Instantly share code, notes, and snippets.

@hellojukay
Last active January 17, 2019 16:12
Show Gist options
  • Save hellojukay/a39a1eb10ccadb658d8aa217c2402b82 to your computer and use it in GitHub Desktop.
Save hellojukay/a39a1eb10ccadb658d8aa217c2402b82 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 zhe li zuo ti mu !"
	println(str)
	println(reverse(str))
}

run it

go run main.go

stdout

jiu shi ni , rang wo da ban ye bu shui jiao , zai zhe li zuo ti mu !
! mu ti zuo li zhe 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