Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 49a3619

Browse files
feat: add csharp solution to lc problem: No.0020 (doocs#1931)
1 parent 8fe78a3 commit 49a3619

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Solution {
2+
public bool IsValid(string s) {
3+
Stack<char> stk = new Stack<char>();
4+
foreach (var c in s.ToCharArray()) {
5+
if (c == '(') {
6+
stk.Push(')');
7+
} else if (c == '[') {
8+
stk.Push(']');
9+
} else if (c == '{') {
10+
stk.Push('}');
11+
} else if (stk.Count == 0 || stk.Pop() != c) {
12+
return false;
13+
}
14+
}
15+
return stk.Count == 0;
16+
}
17+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /