add: 220313 [cpp]
This commit is contained in:
parent
cece201f41
commit
a43b370107
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2203)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2203 220312.cpp)
|
||||
ADD_EXECUTABLE(2203 220313.cpp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue