We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 91dcb7d commit 085f285Copy full SHA for 085f285
20. Valid Parentheses.cpp
@@ -0,0 +1,45 @@
1
+#include <bits/stdc++.h>
2
+using namespace std;
3
+
4
+class Solution
5
+{
6
+public:
7
+ bool isValid(string s)
8
+ {
9
+ stack<char> st;
10
+ for (char c : s)
11
12
+ if (c == '(' || c == '{' || c == '[')
13
14
+ st.push(c);
15
+ }
16
+ else
17
18
+ if (st.empty())
19
20
+ return false;
21
22
23
24
+ if (c == ')' && st.top() == '(')
25
26
+ st.pop();
27
28
+ else if (c == '}' && st.top() == '{')
29
30
31
32
+ else if (c == ']' && st.top() == '[')
33
34
35
36
37
38
39
40
41
42
43
+ return st.empty();
44
45
+};
0 commit comments