We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f1b9f60 commit 85dea78Copy full SHA for 85dea78
Target Offer/替换空格.py
@@ -6,6 +6,20 @@
6
# -*- coding:utf-8 -*-
7
class Solution:
8
# s 源字符串
9
+
10
+ # 使用append一次遍历即可替换
11
+ # 由于list的append是O(1)的时间复杂度,除了扩容所导致的时间损耗,该算法复杂度为O(n)
12
+ def replaceSpaceByAppend(self, s):
13
+ string = list(string)
14
+ stringReplace = []
15
+ for item in string:
16
+ if item == ' ':
17
+ stringReplace.append('%')
18
+ stringReplace.append('2')
19
+ stringReplace.append('0')
20
+ else:
21
+ stringReplace.append(item)
22
+ return "".join(stringReplace)
23
24
# 创建新的字符串进行替换
25
def replaceSpace1(self, s):
0 commit comments