I did it like this Golang:
func reverseStr(str string) string {
var reversed string
for i := len(str) - 1; i >= 0; i-- {
reversed += string(str[i])
}
return reversed
}
I'm a beginner and can't do better for now, but I'm still learning. I'd like to know is my method less efficient than the ones I saw online that use runes:
func reverse(s string) string {
chars := []rune(s)
for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
chars[i], chars[j] = chars[j], chars[i]
}
return string(chars)
}