[string]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.
class Solution {
public:
bool isValid(string s) {
stack<char> stk;
int size = s.size();
for(int i=;i<size;i++){
if(s[i]=='('||s[i]=='['||s[i]=='{'){
stk.push(s[i]);
}else{
if(stk.empty()){
return false;
}
char topCh = stk.top();
if((s[i]==']' && topCh=='[' )||
(s[i]==')' && topCh=='(' )||
(s[i]=='}' && topCh=='{' )
){
stk.pop();
}else{
return false;
}
}
}
return stk.empty()? true:false;
}
};
[string]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: ...
随机推荐
- linux重要的标准目录和文件
linux重要的标准目录和文件 / 根目录,所有其他文件在根文件系统的子目录下 /bin 基本命令的二进制文件,存放linux下常用的命令和工具 /boot 引导加载器的固有文件,linux就是从这里 ...
- JQ 替换节点
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- oracle几个函数整理 DECODE() NVL NVL2 NULLIF Coalesce(转)
DECODE() decode()函数简介: 主要作用:将查询结果翻译成其他值(即以其他形式表现出来,以下举例说明): 使用方法: Select decode(columnname,值1,翻译值1,值 ...
- Android之日期及时间选择对话框
转:http://www.cnblogs.com/linjiqin/archive/2011/03/10/1980215.html main.xml布局文件 <?xml version=&quo ...
- section 模块页面切换代码
<div class="blockcode"><blockquote><!DOCTYPE html><html><head&g ...
- 是一个IPV6地址
每次在VS上调试,发现本机地址是 ::1 这种就不解.由于太忙而没关注,今天看了IPV6的文章才明白.原来这是个IPV6地址,也就是本机环回地址.以前是127.0.0.1,IPV4版本,而IPV6的就 ...
- NPOI导出多张图片到Excel
常用NPOI导出数据到excel,但没有试过如何导出图片.NPOI最大的特点就是不依赖于Excel组件,服务端不需要安装Excel.在单元格中插入图片主要是用HSSFClientAnchor对象.他有 ...
- ISP图像质量自动化测试方法
背景介绍 ISP(Image Signal Processor),即图像处理,主要作用是对前端图像传感器输出的信号做后期处理,主要功能有线性纠正.噪声去除.坏点去除.内插.白平衡.自动曝光控制等,依赖 ...
- 一个Java项目的学习
1. java命令行的启动 首先是gradle build 其次是:java -Dabc.appid=1234 -classpath "a.jar:b.jar" com.ctri ...
- Nginx安装配置PHP(FastCGI)环境的教程
这篇是Nginx安装配置PHP(FastCGI)环境的教程.Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用. 一.什么是 FastCGI F ...