Skip to content

Commit 52aae55

Browse files
authored
feat: added solutions to lc problem: No.0020
Created file solution.cs for C# solution to lc problem: No.0020
1 parent adbc216 commit 52aae55

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)