Skip to content

Commit c1c72af

Browse files
authored
feat: add solution to lcof problem: No.05 (#655)
1 parent 1394ddf commit c1c72af

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lcof/面试题05. 替换空格/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,26 @@ public:
131131
132132
### **TypeScript**
133133
134+
- 使用 `replace()`
135+
134136
```ts
135137
function replaceSpace(s: string): string {
136138
return s.replace(/\s/g, "%20");
137139
}
138140
```
139141

142+
- 遍历添加
143+
144+
```ts
145+
function replaceSpace(s: string): string {
146+
const strArr = [];
147+
for (const c of s) {
148+
strArr.push(c === " " ? "%20" : c);
149+
}
150+
return strArr.join("");
151+
}
152+
```
153+
140154
### **...**
141155

142156
```

0 commit comments

Comments
 (0)