Monday, December 19, 2022
A function that reverses a string. The input string is given as an array of characters (bytes) s
.
func reverseString(s []byte) string {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
return string(s)
}