leet-code/reverse-string/sol.go

13 lines
174 B
Go
Raw Permalink Normal View History

2021-11-08 13:00:57 +00:00
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
}
}