classSolution{public:boolbackspaceCompare(stringS,stringT){inti=S.length()-1;// S's indexintj=T.length()-1;// T's indexwhile(true){// Delete chars of S if neededintback=0;while(i>=0&&(S[i]=='#'||back>0)){back+=S[i]=='#'?1:-1;--i;}// Delete chars of T if neededback=0;while(j>=0&&(T[j]=='#'||back>0)){back+=T[j]=='#'?1:-1;--j;}if(i>=0&&j>=0&&S[i]==T[j]){--i;--j;}else{break;}}returni==-1&&j==-1;}};