Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]" are not.
Subscribe to see which companies asked this question
class Solution {
public:
bool isValid(string s) {
stack<char> store;
for (auto c : s) {
if (c == '(' || c == '{' || c == '[')
store.push(c);
else {
if (store.empty()) return false;
if (c == ')' && store.top() == '('){
store.pop();
}
else if (c == '}' && store.top() == '{'){
store.pop();
}
else if (c == ']' && store.top() == '['){
store.pop();
}
else
return false;
}
}
return store.empty();
}
};
Valid Parentheses的更多相关文章
- [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 ...
- [LintCode] Valid Parentheses 验证括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- Longest Valid Parentheses 每每一看到自己的这段没通过的辛酸代码
Longest Valid Parentheses My Submissions Question Solution Total Accepted: 47520 Total Submissions: ...
- [LeetCode] Longest Valid Parentheses 动态规划
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
随机推荐
- 经验分享:使用 Restyle.js 简化 CSS 预处理
Andrea Giammarchi的restyle.js是一个新的,基于JavaScript的CSS预处理器,能够运行在服务端(通过Node.js)或者浏览器中.它宣称自己是“一种简化的CSS方法”, ...
- PHP FTP操作类( 上传、拷贝、移动、删除文件/创建目录 )
/** * 作用:FTP操作类( 拷贝.移动.删除文件/创建目录 ) * 时间:2006/5/9 * 作者:欣然随风 * QQ:276624915 */ class class_ftp { publi ...
- 设置ASP.NET MVC站点默认页为html页
问题由来 部署了一个Asp.Net MVC的站点,其功能只是作为移动端的服务器,服务器空间里面除了CMS以外就没有其他的页面了.这对于我们来说确实是有点浪费了. 可以放点静态的啥小东西放在上面玩一玩. ...
- C#抽象类、抽象方法、抽象属性
定义 在C#中使用关键字 abstract 来定义抽象类和抽象方法. 不能初始化的类被叫做抽象类,它们只提供部分实现,但是另一个类可以继承它并且能创建它们的实例."一个包含一个或多个纯虚函数 ...
- PostgreSQL数据库系统优点
PostgreSQL 是世界上可以获得的最先进的开放源码的数据库系统, 它提供了多版本并行控制,支持几乎所有 SQL 构件(包括子查询,事务和用户定 义类型和函数), 并且可以获得非常广阔范围的(开发 ...
- bzoj 2132: 圈地计划
#include<cstdio> #include<iostream> #include<cstring> #define M 100009 #define inf ...
- wp8.1 Study10:APP数据存储
一.理论 1.App的各种数据在WP哪里的? 下图很好介绍了这个问题.有InstalltionFolder, knownFolder, SD Card... 2.一个App的数据存储概览 主要分两大部 ...
- 最新的goldengate monitor 12.1.3已经发布
Oracle GoldenGate管理包针对OGG提供企业级的监控和管理,包含有如下模块: Oracle Enterprise Manager Plug-in. 利用OEM框架查看.管理和预警OGG ...
- zoj1610 线段树
//Accepted 804 KB 40 ms //整个题,都是坑 //1.The first line of each data set contains exactly one integer n ...
- PHP四舍五入精确小数位及取整
php中取小数位的函数有sprintf,ceil,floor,round等等函数来实现四舍五入,下面我们就一起来看看具体的实例吧. 本篇文章将使用php对数字进行四舍五入保留N位小数,以及使用 ...