//Go funcreplaceSpace(s string)string { ans := "" //一次循环,遇到' ',给当前字符串尾部加上 "%20" for _,v := range s{ if v == ' '{ ans = ans + "%20" } else { ans = ans + string(v) } } return ans }
leetcode-执行:
1 2 3 4
执行用时: 0 ms, 在所有 Go 提交中击败了100.00%的用户 内存消耗: 3.4 MB, 在所有 Go 提交中击败了16.95%的用户