File tree 1 file changed +14
-13
lines changed
solution/0000-0099/0020.Valid Parentheses
1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -232,21 +232,22 @@ impl Solution {
232
232
233
233
### ** C#**
234
234
235
- ``` C#
235
+ ``` cs
236
236
public class Solution {
237
237
public bool IsValid (string s ) {
238
- Stack < char > ch = new Stack <char >();
239
- foreach (var item in s .ToCharArray ())
240
- if (item == '(' )
241
- ch .Push (')' );
242
- else if (item == '[' )
243
- ch .Push (']' );
244
- else if (item == '{' )
245
- ch .Push ('}' );
246
- else if (ch .Count == 0 || ch .Pop () != item )
247
- return false ;
248
-
249
- return ch .Count == 0 ;
238
+ Stack < char > stk = new Stack <char >();
239
+ foreach (var c in s .ToCharArray ()) {
240
+ if (c == '(' ) {
241
+ stk .Push (')' );
242
+ } else if (c == '[' ) {
243
+ stk .Push (']' );
244
+ } else if (c == '{' ) {
245
+ stk .Push ('}' );
246
+ } else if (stk .Count == 0 || stk .Pop () != c ) {
247
+ return false ;
248
+ }
249
+ }
250
+ return stk .Count == 0 ;
250
251
}
251
252
}
252
253
```
You can’t perform that action at this time.
0 commit comments