diff options
author | crupest <crupest@outlook.com> | 2021-02-23 21:07:19 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-23 21:07:19 +0800 |
commit | d8f3b40085619cb680c8f227c65a1f5acc393223 (patch) | |
tree | 6a38e3a6c79276fc396259ef962d17236dbed569 /cpp/20.cpp | |
parent | b0162802ad9723c678e495f29ca2f0fc0af2eff1 (diff) | |
download | solutions-d8f3b40085619cb680c8f227c65a1f5acc393223.tar.gz solutions-d8f3b40085619cb680c8f227c65a1f5acc393223.tar.bz2 solutions-d8f3b40085619cb680c8f227c65a1f5acc393223.zip |
Move leetcode solutions to subdir.
Diffstat (limited to 'cpp/20.cpp')
-rw-r--r-- | cpp/20.cpp | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/cpp/20.cpp b/cpp/20.cpp deleted file mode 100644 index e994e96..0000000 --- a/cpp/20.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include <string>
-
-using std::string;
-
-#include <stack>
-
-class Solution
-{
-public:
- inline static char get_companion(char c)
- {
- switch (c)
- {
- case ')':
- return '(';
- case ']':
- return '[';
- default:
- return '{';
- }
- }
-
- bool isValid(string s)
- {
- std::stack<char> stack;
-
- for (const auto c : s)
- {
- switch (c)
- {
- case '(':
- case '[':
- case '{':
- {
- stack.push(c);
- break;
- }
- case ')':
- case ']':
- default:
- {
- if (stack.empty())
- return false;
- const auto top = stack.top();
- const char companion = get_companion(c);
- if (top != companion)
- return false;
- stack.pop();
- }
- }
- }
-
- return stack.empty();
- }
-};
|