diff --git a/cpp/2203/220313.cpp b/cpp/2203/220313.cpp new file mode 100644 index 0000000..f19f44b --- /dev/null +++ b/cpp/2203/220313.cpp @@ -0,0 +1,34 @@ +#include +#include + +class Solution { +public: + static bool isValid(const std::string& s) { + char pairs[256]{}; + '}'[pairs] = '{'; + ']'[pairs] = '['; + ')'[pairs] = '('; + + std::stack 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; +} diff --git a/cpp/2203/CMakeLists.txt b/cpp/2203/CMakeLists.txt index 3accb46..cbdae08 100644 --- a/cpp/2203/CMakeLists.txt +++ b/cpp/2203/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2203) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2203 220312.cpp) +ADD_EXECUTABLE(2203 220313.cpp)