File tree 2 files changed +44
-0
lines changed
solution/0000-0099/0020.Valid Parentheses
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,28 @@ impl Solution {
252
252
}
253
253
```
254
254
255
+ ### ** C#**
256
+
257
+ ``` cs
258
+ public class Solution {
259
+ public bool IsValid (string s ) {
260
+ Stack < char > stk = new Stack <char >();
261
+ foreach (var c in s .ToCharArray ()) {
262
+ if (c == '(' ) {
263
+ stk .Push (')' );
264
+ } else if (c == '[' ) {
265
+ stk .Push (']' );
266
+ } else if (c == '{' ) {
267
+ stk .Push ('}' );
268
+ } else if (stk .Count == 0 || stk .Pop () != c ) {
269
+ return false ;
270
+ }
271
+ }
272
+ return stk .Count == 0 ;
273
+ }
274
+ }
275
+ ```
276
+
255
277
### ** ...**
256
278
257
279
```
Original file line number Diff line number Diff line change @@ -230,6 +230,28 @@ impl Solution {
230
230
}
231
231
```
232
232
233
+ ### ** C#**
234
+
235
+ ``` cs
236
+ public class Solution {
237
+ public bool IsValid (string s ) {
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 ;
251
+ }
252
+ }
253
+ ```
254
+
233
255
### ** ...**
234
256
235
257
```
You can’t perform that action at this time.
0 commit comments