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 adbc216 commit 52aae55Copy full SHA for 52aae55
solution/0000-0099/0020.Valid Parentheses/solutions.cs
@@ -0,0 +1,16 @@
1
+public class Solution {
2
+ public bool IsValid(string s) {
3
+ Stack<char> ch = new Stack<char>();
4
+ foreach (var item in s.ToCharArray())
5
+ if (item == '(')
6
+ ch.Push(')');
7
+ else if (item == '[')
8
+ ch.Push(']');
9
+ else if (item == '{')
10
+ ch.Push('}');
11
+ else if (ch.Count == 0 || ch.Pop() != item)
12
+ return false;
13
+
14
+ return ch.Count == 0;
15
+ }
16
+}
0 commit comments