-
Notifications
You must be signed in to change notification settings - Fork 0
844_BackspaceStringCompare
a920604a edited this page Apr 14, 2023
·
1 revision
class Solution {
public:
string process(string s){
string ret ;
for(char c:s){
if(c=='#'){
if(!ret.empty()) ret.pop_back();
}
else ret+=c;
}
return ret;
}
bool backspaceCompare(string s, string t) {
string ret, ans;
string a = process(s), b = process(t);
return a==b;
}
};
- time complexity
O(n)
- space complexity
O(n)
footer