LintCode: Valid Parentheses
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的更多相关文章
- [LintCode] Valid Parentheses 验证括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- 423. Valid Parentheses【LintCode java】
Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine ...
- [LeetCode] Longest Valid Parentheses 最长有效括号
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- [LeetCode] Valid Parentheses 验证括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- 72. Generate Parentheses && Valid Parentheses
Generate Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', ...
- leetcode 32. Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- 【leetcode】Longest Valid Parentheses
Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length ...
- 【leetcode】 Longest Valid Parentheses (hard)★
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
随机推荐
- ASP.NET Web API实践系列03,路由模版, 路由惯例, 路由设置
ASP.NET Web API的路由和ASP.NET MVC相似,也是把路由放在RouteTable中的.可以在App_Start文件夹中的WebApiConfig.cs中设置路由模版.默认的路由模版 ...
- SpringBoot 中使用 @Value 为 static 变量赋值
原文:https://www.jianshu.com/p/ea477fc9abf7 例如: public class Utils { @Value("${test.host}") ...
- iReport使用方法
新建报表,依次单击“文件/New…”,弹出窗口 选择”Blank A4”,单击”Open this Template” 依次单击“下一步/完成”,得到一个新的report 单击”OK”按钮完成数据集设 ...
- JQuery日期插件
JQuery是一款非常优秀的脚本框架,其丰富的控件使用起来也非常简单,配置非常灵活.下面做一个使用日期插件datapicker的例子. 1.下载jQuery核心文件就不用说了吧,datepicker是 ...
- MySQL到Greenplum迁移分析
MySQL到Greenplum迁移分析 1 数据类型对比 MySQL PostgreSQL comments 数值类型 TINYINT SMALLINT gp中无zerofill属性及unsign ...
- 获取客户端网卡MAC地址和IP地址实现JS代码
获取客户端网卡MAC地址和IP地址实现JS代码 作者: 字体:[增加 减小] 类型:转载 获取客户端的一些信息,如IP和MAC,以结合身份验证,相信很多人都会这样做吧,我们这里用Javascrip ...
- CDR话单主要字段介绍
l Time of call connection RRC连接时的时间,格式:yyyy年mm月dd日hh时mm分ss秒 l Call Setup Time per sections 呼叫建立时长 ...
- golang的日志系统log和glog
go语言有一个标准库,log,提供了最基本的日志功能,但是没有什么高级的功能,如果需要高级的特性,可以选择glog或log4go. 参考:https://cloud.tencent.com/devel ...
- 【ContestHunter】【弱省胡策】【Round0】(A)&【Round1】(B)
DP+容斥原理or补集转化?/KD-Tree 唔……突然发现最早打的两场(打的最烂的两场)没有写记录……(太烂所以不忍记录了吗... 还是把搞出来了的两道题记录一下吧= =勉强算弥补一下缺憾…… Ro ...
- 关于NLP和深度学习,准备好好看看这个github,还有这篇介绍
这个github感觉很不错,把一些比较新的实现都尝试了: https://github.com/brightmart/text_classification fastText TextCNN Text ...