Reverse String

Write a function that reverses a string. The input string is given as an array of characters s.

Solution in Go

func reverseString(s []byte)  {
    for i := 0; i < len(s) / 2; i++ {
        s[i], s[len(s) - 1 - i] = s[len(s) - 1 - i], s[i]
    }
}
Subscribe via email

Get notified once/twice per month when new articles are published.

Copyright © 2022 - 2024 TheDeveloperCafe.
The Go gopher was designed by Renee French.