C++

stack<char|int|string>, push(), pop(), top(), empty(), size()

 class Solution {
public:
/**
* @param s A string
* @return whether the string is a valid parentheses
*/
bool isValidParentheses(string& s) {
// Write your code here
stack<char> sta;
for (int i = ; i < s.size(); i++) {
if (s[i] == '(' || s[i] == '{' || s[i] == '[') {
sta.push(s[i]);
continue;
}
char top = sta.top();
sta.pop();
if (s[i] == ')' && top != '(') return false;
if (s[i] == ']' && top != '[') return false;
if (s[i] == '}' && top != '{') return false;
}
return sta.empty();
}
};

LintCode: Valid Parentheses的更多相关文章

  1. [LintCode] Valid Parentheses 验证括号

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  2. 423. Valid Parentheses【LintCode java】

    Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine ...

  3. [LeetCode] Longest Valid Parentheses 最长有效括号

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  4. [LeetCode] Valid Parentheses 验证括号

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  5. Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  6. 72. Generate Parentheses && Valid Parentheses

    Generate Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', ...

  7. leetcode 32. Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  8. 【leetcode】Longest Valid Parentheses

    Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length ...

  9. 【leetcode】 Longest Valid Parentheses (hard)★

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

随机推荐

  1. 报错:此版本的SQL Server Data Tools与此计算机中安装的数据库运行时组件不兼容

    在Visual Studio 2012中使用Entity Framework,根据模型生成数据库时,报如下错误: 无法在自定义编辑器中打开Transact-SQL文件此版本的SQL Server Da ...

  2. Struts2标签的<s:set>标签与JSTL的<c:set>标签

    <s:set>标签 set标签 用于将某个值放入指定范围内.例如application.session范围等. 当某个值所在的对象图深度非常深时,例如如下:person.worker.wi ...

  3. input输入框只能输入正整数正则

    input输入框加入限制只能输入正整数,输入其他字符会自动清除: <input type="text" value="1" onkeyup="i ...

  4. SQLite中的事务操作

    关于SQLite事务可以解决一些问题,比如你要插入两个数据,可以将两个数据作为同一个事务进行插入,这样如果第二个数据错误了,便自动执行回滚操作,第一个数据也不会插入成功,保证了数据的同步! 一.实际的 ...

  5. [DEFCON全球黑客大会] 针对CTF,大家都是怎么训练的?

    https://www.zhihu.com/question/30505597 https://www.zhihu.com/question/42067737

  6. .Net Excel操作之NPOI(二)常用操作封装

    一.Excel数据导出常用操作 1.指定表头和描述 2.指定数据库中读出的数据集合 二.ExcelExport封装 /// <summary> /// Excel常用的表格导出逻辑封装 / ...

  7. 让Android Preference Summary中实时显示内容变更

    Android中提供的Preference可以保存用户的喜好设置.在启明星安卓版员工通讯录里,有一个地方保存用户输入的URL就是用的Preference. 但是Preference默认显示的是Summ ...

  8. Netty Associated -- ChannelPipeline

    A list of ChannelHandlers which handles or intercepts inbound events and outbound operations of a Ch ...

  9. verilog语法实例学习(6)

    函数和任务 函数 https://wenku.baidu.com/view/d31d1ba8dd3383c4bb4cd283.html verilog中函数的目的是允许代码写成模块的方式而不是定义独立 ...

  10. Kyoto Cabinet 使用及原理

    Kyoto Cabinet 基本规格书 如果你知道 Tokyo Cabinet ,那么就应该知道 Kyoto Cabinet,因为他们都是同一个作者(平林幹雄)开发出来的 Key-Value 数据库. ...