O(n^2) On Thursday, 27 February 2020 18:53:01 UTC, rog wrote: > > If you really just want to reverse rune-by-rune, it's pretty > straightforward: > > func Reverse(s string) string { > r := make([]byte, 0, len(s)) > for len(s) > 0 { > _, n := utf8.DecodeLastRuneInString(s) > i := len(s) - n > r = append(r, s[i:]...) > s = s[:i] > } > return string(r) > } > > That will also deal correctly with invalid utf8 encoding - all the bytes > of the original string will be present in the result. > >> >> >>
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/2333bc33-8740-4f8b-972e-37d2d60b9dc7%40googlegroups.com.