Skip to content

Commit 0eedd5d

Browse files
authored
Merge pull request shruti170901#73 from ronakagarwal3434/master
added solutions
2 parents d419267 + d1d0f0f commit 0eedd5d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Diff for: Backspace String Compare

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
bool backspaceCompare(string S, string T) {
4+
int i = S.size() - 1, j = T.size() - 1, countA = 0, countB = 0;
5+
while(i >= 0 || j >= 0){
6+
while(i >= 0 && (S[i] == '#' || countA > 0)) S[i--] == '#' ? ++countA : --countA;
7+
while(j >= 0 && (T[j] == '#' || countB > 0)) T[j--] == '#' ? ++countB : --countB;
8+
if(i < 0 || j < 0) return i == j;
9+
if(S[i--] != T[j--]) return false;
10+
}
11+
return i == j;
12+
}
13+
};

0 commit comments

Comments
 (0)