Skip to content

Commit b9c72f7

Browse files
authored
Create Readme.md
1 parent 19b540e commit b9c72f7

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### 844.Backspace-String-Compare
2+
3+
此题的考点是用o(n)时间和o(1)空间.这就提示我们做in-place的修改.
4+
5+
我们可以尝试用双指针的方法,将有效的字符移动到字符串的后面.快指针移动的规则是利用一个count来记录所扫过的退格符的个数:
6+
```
7+
while (count>0 || i>=0 && S[i]=='#')
8+
{
9+
if (S[i]=='#')
10+
count++
11+
else
12+
count--;
13+
i--;
14+
}
15+
```
16+
当快指针停止时,就可以赋值给慢指针,并将两个指针同时减一.

0 commit comments

Comments
 (0)