-
-
Save alextanhongpin/0b72edcffda642abcd8deba81aced0c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This program demonstrates how to reverse string in go | |
package main | |
import "log" | |
func main() { | |
log.Println(reverse("hello world!")) | |
} | |
func reverse(s string) string { | |
r := []rune(s) | |
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 { | |
r[i], r[j] = r[j], r[i] | |
} | |
return string(r) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment