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的更多相关文章

  1. [LintCode] Valid Parentheses 验证括号

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  2. 423. Valid Parentheses【LintCode java】

    Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine ...

  3. [LeetCode] Longest Valid Parentheses 最长有效括号

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  4. [LeetCode] Valid Parentheses 验证括号

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  5. Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  6. 72. Generate Parentheses && Valid Parentheses

    Generate Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', ...

  7. leetcode 32. Longest Valid Parentheses

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

  8. 【leetcode】Longest Valid Parentheses

    Longest Valid Parentheses Given a string containing just the characters '(' and ')', find the length ...

  9. 【leetcode】 Longest Valid Parentheses (hard)★

    Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...

随机推荐

  1. 再议ASP.NET MVC中CheckBoxList的验证

    在ASP.NET MVC 4中谈到CheckBoxList,经常是与CheckBoxList的显示以及验证有关.我在"MVC扩展生成CheckBoxList并水平排列"中通过扩展H ...

  2. Arcgis for JavascriptAPI 常用接口

    转自原文arcgis for javascriptAPI常用接口 var map, navToolbar, editToolbar, tileLayer, toolbar; //var mapBase ...

  3. C#编程(四十二)----------委托和事件

    委托和事件 委托是C#总比较重要的概念,学习C#爱这里最容易产生迷惑. 有些时候,犹豫我们在开发程序时对后续可能出现的要求及变化考虑不足而导致麻烦,这些新变化可能导致程序的重新编写,那能不能改变这种情 ...

  4. C#编程(二十八)----------泛型类的功能

    泛型类的功能 在创建泛型类时,还需要一些其他的C#关键字.例如,不能把null赋予泛型类型.此时,可以使用default关键字.如果泛型类型不需要object类的功能,但需要调用泛型类上的某些特定方法 ...

  5. Kali Linux 与 BackTrack Linux

     (一)BackTrack BackTrack是基于Ubuntu的自启动运行光盘,它包含了一套安全及计算机取证工具.它其实是依靠融合Auditor Security Linux和WHAX(先前的Who ...

  6. HDR和bloom效果的区别和关系

    什么是HDR?        谈论游戏画面时常说的HDR到底是什么呢?HDR,本身是High-Dynamic Range(高动态范围)的缩写,这本来是一个CG概念.HDR的含义,简单说,就是超越普通的 ...

  7. nginx反向代理vue访问时浏览器加载失败,出现 ERR_CONTENT_LENGTH_MISMATCH 问题

    问题说明:测试机上部署了一套业务环境,nginx反向代理tomcat,在访问时长时间处于加载中,十分缓慢! 通过浏览器调试(F12键->Console),发现有错误ERR_CONTENT_LEN ...

  8. java把指定文字输出为图片流,支持文字换行

    public class IamgeUtils { private static final int WIDTH = 350; private static final int HEIGHT = 10 ...

  9. Charles抓包https

    Charles抓包https 灰灰是只小贱狗 2018.05.08 10:46 字数 762 阅读 7800评论 3喜欢 3 抓取HTTPS请求包,对数据进行排查检验 1.安装Charles 2.电脑 ...

  10. Kubernetes基础

    Kubernetes是什么 Kubernetes是当今最流行的开源容器管理平台,它就是大名鼎鼎的Google Borg的开源版本.Google在2014年推出了Kubernetes,本文发布时最新的版 ...