We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f40b55f commit 7aa3b70Copy full SHA for 7aa3b70
valid_parentheses.cpp
@@ -0,0 +1,25 @@
1
+class Solution {
2
+public:
3
+ bool isValid(string s) {
4
+ stack<char> chs;
5
+ for (char ch : s)
6
+ {
7
+ if (ch == '(')
8
+ chs.push(')');
9
+ if (ch == '{')
10
+ chs.push('}');
11
+ if (ch == '[')
12
+ chs.push(']');
13
+ if (ch == ')' || ch == '}' || ch == ']')
14
+ if (chs.empty() || chs.top() != ch)
15
+ return false;
16
+ else
17
18
+ chs.pop();
19
+ }
20
21
+ if (chs.empty())
22
+ return true;
23
24
25
+};
0 commit comments