請(qǐng)實(shí)現(xiàn)一個(gè)函數(shù)洁仗,把字符串 s 中的每個(gè)空格替換成"%20"恰聘。
- 真的牛逼了
執(zhí)行用時(shí) :
28 ms
, 在所有 Python 提交中擊敗了
14.44%
的用戶
內(nèi)存消耗 :
11.7 MB
, 在所有 Python 提交中擊敗了
100.00%
的用戶
- 利用for循環(huán)創(chuàng)建表格义郑,替換后再用join生成新str
class Solution(object):
def replaceSpace(self, s):
list = []
for word in s:
if word == ' ':
list.append('%20')
else:
list.append(word)
return ''.join(list)
- 直接用replace?沒意思了噢
class Solution(object):
def replaceSpace(self, s):
return s.replace(' ','%20')