reverse-string
This commit is contained in:
parent
f9e9a910b7
commit
f15f03b1d6
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue