Website Summary Files Commits Branches @commit @diff @stats
path: root / Practicum / pract06 / solutions / Task 01.cpp
diff options
context:
space:
mode:
1 files changed, 35 insertions, 0 deletions
-rw-r--r--Practicum/pract06/solutions/Task 01.cpp35
diff --git a/Practicum/pract06/solutions/Task 01.cpp b/Practicum/pract06/solutions/Task 01.cpp
new file mode 100644
index 0000000..738b769
--- /dev/null
+++ b/Practicum/pract06/solutions/Task 01.cpp
@@ -0,0 +1,35 @@
+#include <string>
+#include <stack>
+
+class Solution
+{
+public:
+ bool isValid(std::string s)
+ {
+ std::stack<char> open;
+
+ for (char ch : s)
+ {
+ if (ch == '(' || ch == '{' || ch == '[')
+ {
+ open.push(ch);
+ }
+ else
+ {
+ if (open.empty())
+ return false;
+
+ if ((open.top() == '(' && ch == ')') ||
+ (open.top() == '{' && ch == '}') ||
+ (open.top() == '[' && ch == ']'))
+ {
+ open.pop();
+ continue;
+ }
+ return false;
+ }
+ }
+
+ return open.empty();
+ }
+}; \ No newline at end of file