Skip to content

Commit 592d6bc

Browse files
committed
844. 比较含退格的字符串
1 parent 6354be8 commit 592d6bc

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
|700|[二叉搜索树中的搜索](https://leetcode.cn/problems/search-in-a-binary-search-tree/)|[JavaScript](./algorithms/search-in-a-binary-search-tree.js)|Easy|
122122
|704|[二分查找](https://leetcode.cn/problems/binary-search/)|[JavaScript](./algorithms/binary-search.js)|Easy|
123123
|707|[设计链表](https://leetcode.cn/problems/design-linked-list/)|[JavaScript](./algorithms/design-linked-list.js)|Medium|
124+
|844|[比较含退格的字符串](https://leetcode.cn/problems/backspace-string-compare/)|[JavaScript](./algorithms/backspace-string-compare.js)|Easy|
124125
|876|[链表的中间结点](https://leetcode.cn/problems/middle-of-the-linked-list/)|[JavaScript](./algorithms/middle-of-the-linked-list.js)|Easy|
125126
|897|[递增顺序搜索树](https://leetcode.cn/problems/increasing-order-search-tree/)|[JavaScript](./algorithms/increasing-order-search-tree.js)|Easy|
126127
|912|[排序数组](https://leetcode.cn/problems/sort-an-array/)|[JavaScript](./algorithms/sort-an-array.js)|Medium|
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {string} s
3+
* @param {string} t
4+
* @return {boolean}
5+
*/
6+
var backspaceCompare = function (s, t) {
7+
let sStr = "";
8+
let tStr = "";
9+
10+
for (let c of s) {
11+
if (c === "#") {
12+
sStr = sStr.slice(0, -1);
13+
} else {
14+
sStr += c;
15+
}
16+
}
17+
for (let c of t) {
18+
if (c === "#") {
19+
tStr = tStr.slice(0, -1);
20+
} else {
21+
tStr += c;
22+
}
23+
}
24+
25+
return sStr === tStr;
26+
};

0 commit comments

Comments
 (0)