-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path844.cpp
More file actions
27 lines (27 loc) · 721 Bytes
/
844.cpp
File metadata and controls
27 lines (27 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
bool backspaceCompare(string s, string t) {
stack<char> sStack;
stack<char> tStack;
for (auto c : s) {
if (c == '#') {
if (!sStack.empty()) sStack.pop();
}
else (sStack.push(c));
}
for (auto c : t) {
if (c == '#') {
if (!tStack.empty()) tStack.pop();
}
else (tStack.push(c));
}
if (sStack.size() != tStack.size()) return false;
int n = sStack.size();
while (n--) {
if (sStack.top() != tStack.top()) return false;
sStack.pop();
tStack.pop();
}
return true;
}
};