public class Solution
{
public int MinAddToMakeValid(string S)
{
Stack<char> ST = new Stack<char>();
foreach (var s in S)
{
if (s.Equals('('))
{
ST.Push(s);
}
else//')'
{
if (ST.Count > )
{
var c = ST.Peek();
if (c.Equals('('))
{
ST.Pop();
}
else
{
ST.Push(s);
}
}
else
{
ST.Push(s);
}
}
}
int count = ST.Count;
while (ST.Any())
{
var st = ST.Pop();
}
return count;
}
}

leetcode921的更多相关文章

  1. [Swift]LeetCode921.使括号有效的最少添加 | Minimum Add to Make Parentheses Valid

    Given a string S of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', ...

  2. leetcode921. 使括号有效的最少添加

    题目描述: 给定一个由 '(' 和 ')' 括号组成的字符串 S,我们需要添加最少的括号( '(' 或是 ')',可以在任何位置),以使得到的括号字符串有效. 从形式上讲,只有满足下面几点之一,括号字 ...

随机推荐

  1. RoR unobtrusive scripting adapter--UJS(一些Javascript的语法糖)

    Learn how the new Rails UJS library works and compares with the old version of jquery_ujs that it re ...

  2. linux 常用操作以及概念

    一.常用操作以及概念 查看LINUX发行版的名称及其版本号的命令: lsb_release -a cat /etc/redhat-release(针对redhat,Fedora) 0.rpm包路径:/ ...

  3. kindEditor富文本编辑器

    用法参考:http://kindeditor.net/docs/usage.html  一.使用 . 修改HTML页面 在需要显示编辑器的位置添加textarea输入框. <textarea i ...

  4. nmcli 命令的基本使用

    nmcli命令 地址配置工具:nmcli nmcli  device  查看所有网卡的信息 nmcli  device  status 和numcli device 相同 nmcli  device ...

  5. layui table 数据表格 隐藏列

    现在国内的模板,也就layui一家独大了,其中的数据表格功能强大,但我不会用python或者django拼接json,输出发送给数据表格,那只好用笨办法,循环遍历吧. 数据表格中保留id列,是为了编辑 ...

  6. Roofline Model与深度学习模型的性能分析

    原文链接: https://zhuanlan.zhihu.com/p/34204282 最近在不同的计算平台上验证几种经典深度学习模型的训练和预测性能时,经常遇到模型的实际测试性能表现和自己计算出的复 ...

  7. GPU Memory Usage占满而GPU-Util却为0的调试

    最近使用github上的一个开源项目训练基于CNN的翻译模型,使用THEANO_FLAGS='floatX=float32,device=gpu2,lib.cnmem=1' python run_nn ...

  8. 在win10下安装双系统ubuntu16.04.3教程

    闲暇了两天,终于想起来要装一个Liunx系统了.于是捣鼓了一番,实现了在Win10下安装Ubuntu16.04.3版本. 一.准备工作 下载Ubuntu 16.04.3镜像 准备一个2G以上的U盘 下 ...

  9. [笔记] linux中的计划任务crontab

    不能拒绝进步 cron来源于希腊单词chronos(意为"时间"),指linux系统下一个自动执行指定任务的程序(计划任务). 1--crontab 的命令选项 #crontab ...

  10. 都是用 DllImport?有没有考虑过自己写一个 extern 方法?

    你做 .NET 开发的时候,一定用过 DllImport 这个特性吧,这货是用于 P/Invoke (Platform Invoke, 平台调用) 的.这种 DllImport 标记的方法都带有一个 ...