Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 695b00d

Browse files
committed
feat: add solution for backspace string compare 844
1 parent bd8551e commit 695b00d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

844_backspace-string-compare.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function backspaceCompare(s: string, t: string): boolean {
2+
// initialize first and second string array
3+
let firstString: string[] = [];
4+
let secondString: string[] = [];
5+
6+
// iterate the first string
7+
for (let c of s) {
8+
c !== "#" ? firstString.push(c) : firstString.pop();
9+
}
10+
11+
// iterate the second string
12+
for (let c of t) {
13+
c !== "#" ? secondString.push(c) : secondString.pop();
14+
}
15+
16+
// check the value of first and second string
17+
return firstString.join("") === secondString.join("");
18+
}
19+
20+
console.log(backspaceCompare("ab#c", "ad#c")); // true
21+
console.log(backspaceCompare("ab##", "c#d#")); // true
22+
console.log(backspaceCompare("a##c", "#a#c")); // true
23+
console.log(backspaceCompare("a#c", "b")); //

0 commit comments

Comments
 (0)