File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
scripts/algorithms/B/Backspace String Compare Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 0 ms (Top 100.00%) | Memory: 6.4 MB (Top 28.52%)
1
2
class Solution {
2
3
public:
3
4
bool backspaceCompare (string s, string t) {
4
5
stack<int > st1;
5
6
stack<int > st2;
6
7
int len = s.length ();
7
8
int len2 = t.length ();
8
-
9
+
9
10
for (int i=0 ; i<len; i++){
10
11
if (s[i] != ' #' ){
11
12
st1.push (s[i]);
12
13
}
13
14
else {
14
15
if (!st1.empty ()){
15
- st1.pop ();
16
+ st1.pop ();
16
17
}
17
18
}
18
19
}
@@ -22,11 +23,11 @@ class Solution {
22
23
}
23
24
else {
24
25
if (!st2.empty ()){
25
- st2.pop ();
26
+ st2.pop ();
26
27
}
27
28
}
28
29
}
29
-
30
+
30
31
while (!st1.empty () && !st2.empty ()){
31
32
if (st1.top () != st2.top ()){
32
33
return false ;
@@ -39,4 +40,4 @@ class Solution {
39
40
}
40
41
return false ;
41
42
}
42
- };
43
+ };
You can’t perform that action at this time.
0 commit comments