You are viewing a single comment's thread. Return to all comments →
How the hell is this wrong?
public static string isBalanced(string s) { bool isBalanced = true; int count = 0; Console.WriteLine(s); Stack myStack = new Stack(); Dictionary<char,char> myDict = new Dictionary<char,char>(); myDict.Add(')','('); myDict.Add('}','{'); myDict.Add(']','['); for(int i = 0; i < s.Length; i++){ if(myDict.ContainsKey(s[i]) && count > 0) { if(Convert.ToChar(myStack.Pop())!=myDict.GetValueOrDefault(s[i])) isBalanced = false; count--; } else { myStack.Push(s[i]); count++; } } return (isBalanced) ? "YES" : "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Balanced Brackets
You are viewing a single comment's thread. Return to all comments →
How the hell is this wrong?