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 ...
随机推荐
- 使用cat读取和echo写内核文件节点的一些问题
span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }.CodeMirror ...
- 如何选择使用IEnumerable, ICollection, IList
IEnumerable, ICollection, IList,每种接口只适合某些特定场景,如何区别使用呢? IEnumerable接口,只提供了一个获取迭代器的方法,这也是为什么可以使用foreac ...
- Spring Cloud Gateway服务网关
原文:https://www.cnblogs.com/ityouknow/p/10141740.html Spring 官方最终还是按捺不住推出了自己的网关组件:Spring Cloud Gatewa ...
- 集群服务器下使用SpringBoot @Scheduled注解定时任务
原文:https://blog.csdn.net/huyang1990/article/details/78551578 SpringBoot提供了 Schedule模块完美支持定时任务的执行 在实际 ...
- MAC系统压缩文件传到WINDOWS下出现乱码
可能使用Mac系统的朋友,在压缩文件时遇到过这样的问题: 要给朋友传文件,而对方又是WIN系统.我们打好包传过去以后,对方解压缩发现中文文件名都成乱码了.这是怎么回事? 原来,Mac下,默认文字编码是 ...
- 应收事物处理删除 SQL 语句
/* Formatted on 2018/3/15 10:07:48 (QP5 v5.256.13226.35538) */ --组织表 SELECT * FROM hr_organization_u ...
- TDD:simply mocking a class is not necessarily the best practice
simply mocking a class is not necessarily the best practice either—it might be better to refactor th ...
- Redis在Mac下的安装与使用方法
首先从Redis官网http://www.redis.io去下载最新版本的Redis安装文件(此处以Redis版本为例进行说明). Redis 2.6.16版本的下载地址:http://downl ...
- C#设置有命令空间的属性
之前被问到一个问题,C#中如何设置android:name这样的属性?我的第一反应是直接setAttribute不就可以了么 SetAttribute(name, value), 可事实上却不行,因为 ...
- Android之针对webview的缓存
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...