剑指 Offer 05. 替换空格
题意
题解
思路:遍历,需要注意golang字符串的遍历
- 时间复杂度:o(n)
空间复杂度:o(1)
func replaceSpace(s string) string {ret := ""for _, v := range s {if v == ' ' {ret += "%20"} else {ret += string(v)}}return ret}
结果:
执行用时:0 ms, 在所有 Go 提交中击败了100.00%的用户
- 内存消耗:3.4 MB, 在所有 Go 提交中击败了7.62%的用户
