Skip to content

Instantly share code, notes, and snippets.

@yshuman1
Created March 13, 2019 07:58
Show Gist options
  • Save yshuman1/2bd29c7111bc967539bf5d0be121068d to your computer and use it in GitHub Desktop.
Save yshuman1/2bd29c7111bc967539bf5d0be121068d to your computer and use it in GitHub Desktop.
func reverse(s string) string {
bytes:=[]byte(s)
i, j :=0, len(bytes)-1
for i < j {
bytes[i], bytes[j] = bytes[j], bytes[i]
i++
j--
}
return string(bytes)
}
func reverseWords(s string) string {
ss := strings.Split(s, " ")
for i, s := range ss{
ss[i] = reverse(s)
}
return strings.Join(ss, " ")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment