[Leetcode] 20. Valid Parentheses(Stack)

括号匹配问题,使用栈的特点,匹配则出栈,否则入栈,最后栈为空则全部匹配。代码如下:
class Solution {
public:
bool isValid(string s) {
stack<char> T;
for(int i = ;i < s.length();i ++)
{
if((T.empty()) || (s[i] == T.top()) || abs(s[i] - T.top()) > )
{
T.push(s[i]);
}
else T.pop();
}
if(T.empty())
return true;
else
return false;
}
};
[Leetcode] 20. Valid Parentheses(Stack)的更多相关文章
- 20. Valid Parentheses(stack)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- LeetCode 20 Valid Parentheses (括号匹配问题)
题目链接 https://leetcode.com/problems/valid-parentheses/?tab=Description Problem: 括号匹配问题. 使用栈,先进后出! ...
- LeetCode:20. Valid Parentheses(Easy)
1. 原题链接 https://leetcode.com/problems/valid-parentheses/description/ 2. 题目要求 给定一个字符串s,s只包含'(', ')', ...
- leetcode 20. Valid Parentheses 、32. Longest Valid Parentheses 、
20. Valid Parentheses 错误解法: "[])"就会报错,没考虑到出现')'.']'.'}'时,stack为空的情况,这种情况也无法匹配 class Soluti ...
- LeetCode 之 Longest Valid Parentheses(栈)
[问题描写叙述] Given a string containing just the characters '(' and ')', find the length of the longest v ...
- 32. Longest Valid Parentheses (Stack; DP)
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- [LeetCode] 20. Valid Parentheses 验证括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- [LeetCode] 20. Valid Parentheses 合法括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- [leetcode]20. Valid Parentheses有效括号序列
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
随机推荐
- 重装系统后激活win10和office2016
激活win10: 重装的版本和电脑刚买来是的系统一样的话直接联网,过一段时间就会自动激活.如果不一样可以下载Kms工具激活. 激活office2016: 在开始菜单里双击“我的Office”,登录账号 ...
- hdu_3123_GCC
The GNU Compiler Collection (usually shortened to GCC) is a compiler system produced by the GNU Proj ...
- Spirng+SpringMVC+Mybatis(一)
实习之后都是在别人搭配好环境的情况下进行一些业务的编写,脑袋已经不记得如何搭建一个ssm项目的,所以周末有空补了一下. 首先新建一个test数据库,并且在里面插入三条数据.如图下 编写一个User B ...
- tomcat6添加服务
Mysql在导入大量数据的时候就要把tomcat添加成服务 添加服务 在DOS界面下,进入Tomcat解压目录的bin目录 service.bat install
- DevOps - 配置管理 - Ansible
http://www.zsythink.net/archives/category/运维相关/ansible/
- 第一次使用Git上传本地项目到github
看了好多帖子,终于在混乱中找到自己适合的方法......自我感觉这个比较简单. 先安装本地git,官方下载地址:http://git-scm.com/download/ 根据你自己的系统 下载对应版 ...
- redis 带入的挖矿病毒 qW3xT.2 wnTKYg 解决方法
最近我的阿里云ecs 老是收到 云盾态势感知系统检测到异常 top -c 后发现一个 疑似病毒 /tmp/qW3xT.2 看到网友们的解决方案 试过之后效果不错,可以用的 知道wnTKYg是什么鬼之 ...
- JavaScript : CORS和Ajax请求
CORS(Cross-Origin Resource Sharing, 跨源资源共享)是W3C出的一个标准,其思想是使用自定义的HTTP头部让浏览器与服务器进行沟通,从而决定请求或响应是应该成功,还是 ...
- sqlite3 简单实用方法
打开数据库:sqlite3.exe test.db 显示所有表: .tables 退出 sqlite3:.quit 还有个问题,已经打开一个数据库文件了. 不知道如何在不退出命令行的情况下,更换另一个 ...
- 基于OMAPL:Linux3.3内核的编译
基于OMAPL:Linux3.3内核的编译 OMAPL对应3个版本的linux源代码,分别是:Linux-3.3.Linux-2.6.37.Linux2.6.33,这里的差距在于Linux2,缺少SY ...