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 MVC下实现树形导航菜单
在需要处理很多分类以及导航的时候,树形导航菜单就比较适合.例如在汽车之家上: 页面主要分两部分,左边是导航菜单,右边显示对应的内容.现在,我们就在ASP.NET MVC 4 下临摹一个,如下: 实现的 ...
- iPhone开发过程中调试多次Release问题 message sent to deallocated
初级:第一步 为程序添加符号断点 malloc_error_break 方法如下. 目标效果:让程序崩溃时跳转到出错到那一行.但是往往达不到这个效果.不行就继续往下看. At times, wh ...
- uva 10406 Cutting tabletops
Problem D: Cutting tabletops Bever Lumber hires beavers to cut wood. The company has recently receiv ...
- XMLHttpRequest 的使用······
// JavaScript Document /*创建XMLHttpRequest对象 *这段代码的核心分为三步: 1.建立一个变量 xmlHttp 来引用即将创建的 XMLHttpRequest 对 ...
- Android Studio 下载地址
下载地址:https://developer.android.com/sdk/index.html#download 这个网址可以下载需要的东西,FQ的话可以给 xifulinmen@gma ...
- 简单实用UML关系图解
一句话UML,再记不住就要DPP了: 关系 图解 代码 备注 1:继承关系(Generalization) 2:实现关系(Realization) 3:依赖关系(Dependency) ...
- Asp.Net Core获取请求信息/获取请求地址
一.Asp.Net Core 2.0版本中目前HttpRequest是个抽象类 在控制器或视图上下文中获取到的 Request对象,是 DefaultHttpRequest的实例. 定义 如图 : ...
- [转]MySQL导入.sql文件及常用命令
From : http://blog.csdn.net/muziduoxi/article/details/6091202 在MySQL Qurey Brower中直接导入*.sql脚本,是不能一 ...
- 【FTP资源】发现一个ArcGIS相关的FTP。
用谷歌 在搜索 ArcGISEngineRT的时候,发现了一个站点: ftp://ftp.geobc.gov.bc.ca/pub/outgoing/GeoBC_software_distributio ...
- libnids
一.简介 libnids的英文意思是 Network Intrusion Detect System library,即网络入侵监测系统函数库.它是在前面介绍的两种C函数接口库libnet和libpc ...