Backspace String Compare LeetCode solution in C++
1class Solution {2public:3bool backspaceCompare(string s, string t) {4stack<int> st1;5stack<int> st2;6int len = s.length();7int len2 = t.length();89for (int i = 0; i < len; i++) {10if (s[i] != '#') {11st1.push(s[i]);12} else {13if (!st1.empty()) {14st1.pop();15}16}17}18for (int i = 0; i < len2; i++) {19if (t[i] != '#') {20st2.push(t[i]);21} else {22if (!st2.empty()) {23st2.pop();24}25}26}2728while (!st1.empty() && !st2.empty()) {29if (st1.top() != st2.top()) {30return false;31}32st1.pop();33st2.pop();34}35if (st1.empty() && st2.empty()) {36return true;37}38return false;39}40};