Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aa73fc1

Browse files
Create 844. Backspace String Compare.cpp
1 parent 31f4f18 commit aa73fc1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
bool backspaceCompare(string s, string t) {
4+
string temp1 = "";
5+
string temp2 = "";
6+
for(auto i:s){
7+
if(i=='#' && temp1!="") temp1.pop_back();
8+
else if(i!='#'){
9+
temp1.push_back(i);
10+
}
11+
}
12+
for(auto i:t){
13+
if(i=='#' && temp2!="") temp2.pop_back();
14+
else if(i!='#'){
15+
temp2.push_back(i);
16+
}
17+
}
18+
return temp1==temp2;
19+
20+
}
21+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /