-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrackets.cs
More file actions
22 lines (20 loc) · 776 Bytes
/
Copy pathBrackets.cs
File metadata and controls
22 lines (20 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections.Generic;
using System.Linq;
// you can use Console.WriteLine for debugging purposes, e.g.
// Console.WriteLine("this is a debug message");
class Solution {
public int solution(string S) {
List<char> list = new List<char>();
foreach (char c in S){
if (c == '(' || c == '{' || c == '[') list.Add(c);
else if (list.Count == 0) return 0;
else if (c == ')' && list[list.Count - 1] == '('
|| c == '}' && list[list.Count - 1] == '{'
|| c == ']' && list[list.Count - 1] == '[') list.RemoveAt(list.Count-1);
else return 0;
}
if (list.Count == 0) return 1;
else return 0;
}
}