Created
September 24, 2018 06:20
-
-
Save namtx/9a3ab3129afb59b4f28fdcbe2919e414 to your computer and use it in GitHub Desktop.
reverse string (https://leetcode.com/problems/reverse-string/description/)
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
str := "hello" | |
for _, c := range str { | |
fmt.Println(c) | |
} | |
} | |
func reverseString(s string) string { | |
runes := []rune(s) | |
for l, h := 0, len(runes)-1; l < h; l, h = l+1, h-1 { | |
runes[l], runes[h] = runes[h], runes[l] | |
} | |
return string() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment