844. Backspace String Compare 發表於 2023-02-13 | 分類於 leetcode problemsolution123456789101112131415161718class 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; }}; analysis time complexity O(n) space complexity O(n)