Skip to content

Commit 08b7fac

Browse files
committed
Add C++ solution for leetcofde 1003.
1 parent a6dce4d commit 08b7fac

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<vector>
2+
#include<algorithm>
3+
#include<iostream>
4+
using namespace std;
5+
6+
class Solution {
7+
public:
8+
bool isValid(string s) {
9+
string stk; // 用string模拟栈
10+
for (auto& c: s) {
11+
stk += c;
12+
if (stk.size() >= 3 && stk.substr(stk.size() - 3) == "abc")
13+
{
14+
for (int i = 0; i < 3; i++)
15+
stk.pop_back();
16+
}
17+
}
18+
return stk.empty();
19+
}
20+
};
21+
22+
// Test
23+
int main()
24+
{
25+
Solution sol;
26+
string s = "abcabcababcc";
27+
auto res = sol.isValid(s);
28+
cout << (res ? "True" : "False") << endl;
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)