add: 220313 [cpp]

This commit is contained in:
Lam Haoyin 2022-03-13 14:37:41 +08:00
parent cece201f41
commit a43b370107
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 35 additions and 1 deletions

34
cpp/2203/220313.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <string>
#include <stack>
class Solution {
public:
static bool isValid(const std::string& s) {
char pairs[256]{};
'}'[pairs] = '{';
']'[pairs] = '[';
')'[pairs] = '(';
std::stack<char> stack;
for (char c : s) {
switch (c) {
case '(':
case '[':
case '{':
stack.push(c);
break;
default:
if (stack.empty() || pairs[c] != stack.top())
return false;
stack.pop();
}
}
return stack.empty();
}
};
int main() {
int s[10];
5[s] = 111;
}

View File

@ -3,4 +3,4 @@ PROJECT(2203)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2203 220312.cpp)
ADD_EXECUTABLE(2203 220313.cpp)