zoukankan      html  css  js  c++  java
  • 算法 —— 判断括号是否匹配

    计算出 括号不匹配的个数

            [Theory]
            [InlineData("()))))))))))))))))))))))()()))()))))))))()))))))()))()))))(()))))))))))))()))))))(()))))))))()()))))))))))))()))))(())()))))))(()))))()))))))()))()())))())))))))))))()))())(()()())()()())))))()))))())()))()))))))))))))))()())))()))))()))))))()))())()))())))(()))()))))))))())))())))(())()))))()((()))))))((((()())())())(())))))())())))))))())))))()(()))))()))))())))))()())())()))()))))))))()))))))))))()))))())))))(((()))))()))((())))())))))))())))()()())())))))())))())())))))(())())))))))())))()()))))))))))))(())())())))((()))))))(())))()())))()))))(())))(())))))))))))))(())))(())()))))(()))())())))))))()())(()(())())))))))))))))))))))))))((()())))())))())))((()())))()))())()))))())()())))))))))))(()))))))))))))))()))))))()))))))))))))))))(()(()))(()))()))))))()))()()))))))))))()))())()))))())))()()()))()))))(())))))))))))))()()))))(())))()))))))()))()())()))())()())())))()()(()())))))()())))))))())))())))(())))())))))))()))))))))()((()(())))))))))(())))())))())))))))))()())))()))))))))(")]
            public int getMin(string s)
            {
                int p1 = 0;
                var lastOpener = new Stack<char>();
                foreach (char c in s)
                {
                    if (c == '(')
                    {
                        p1++;
                        lastOpener.Push(c);
                    }
                    if (c == ')' )
                    {
                        if (lastOpener.Count > 0 && lastOpener.Pop() == '(')
                        {
                            p1--;
                        }
                        else
                        {
                            p1++;
                        }
                    }
                }
    
                return Math.Abs(p1);
            }
    

      

  • 相关阅读:
    PowerShell Arrays
    PowerShell Hashtable
    PowerShell Variables
    MVC3 类型“System.Web.Mvc.ModelClientValidationRule”同时存在
    神奇的Timer
    神奇的Timer之lock篇
    利用lambda表达式正确关闭WCF连接
    Zendstutio设置
    一个服务器部署多个项目
    Magento模块配置文件
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/14999278.html
Copyright © 2011-2022 走看看