reverse-string

This commit is contained in:
Gleb Koval 2021-11-08 13:00:57 +00:00
parent f9e9a910b7
commit f15f03b1d6
No known key found for this signature in database
GPG Key ID: DF27F6A77C48FDA0
1 changed files with 12 additions and 0 deletions

12
reverse-string/sol.go Normal file
View File

@ -0,0 +1,12 @@
package main
// Time: O(n)
// Space: O(1)
func reverseString(s []byte) {
l := len(s)
for p := 0; p <= (l-1)/2; p++ {
tmp := s[p]
s[p] = s[l-p-1]
s[l-p-1] = tmp
}
}