Find if given text does have matching [ { ( opening and closing. So ({[]}) is valid and ({)} is invalid. They should open and close in proper order.
Anonymous
private static bool OpeningClosingTags(string str) { Dictionary dict = new Dictionary(){{'{',0},{'(',0},{'[',0},{'}',0},{')',0},{']',0}}; Dictionary dict2 = new Dictionary() { { '{', '}' },{'[',']'},{'(',')'} }; foreach(var c in str) { int val=0; if (dict.TryGetValue(c, out val)) dict[c]++; } foreach(var d in dict2) { if (dict[d.Key] != dict[d.Value]) return false; } return true; }
Check out your Company Bowl for anonymous work chats.