计算出 括号不匹配的个数

        [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);
        }

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-12
  • 2022-12-23
  • 2021-07-22
  • 2022-01-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
相关资源
相似解决方案