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. url提交参数类

    url提交参数类 type /// <summary> /// 准备url /// </summary> TynUrl = class private FUrl, FComma ...

  2. 快速将wax配置到项目中进行lua开发

    通过Finder浏览到你保存该项目的文件夹.创建三个新的文件夹:wax.scripts和Classes. 第一:首先,下载源代码的压缩包.Wax放在GitHub上(https://github.com ...

  3. 架构:The Onion Architecture : part 1(洋葱架构:第一篇)(转载)

    原文地址:http://jeffreypalermo.com/blog/the-onion-architecture-part-1/. I've spoken several times about ...

  4. SharePoint 设置客户端上传文件大小

    in sharepoint 2013, 2016 , there is a limitatoin on the size of the uploading files , default size f ...

  5. 神盾局特工第一季/全集Agents Of SHIELD迅雷下载

    神盾局特工 Agents of S.H.I.E.L.D. (2013) 本季看点:如果你熟悉Marvel漫画或者看过创造电影票房记录的<复仇者联盟>(The Avengers),你应该对「 ...

  6. 大西洋帝国第一季/全集Boardwalk Empire1迅雷下载

    大西洋帝国 第一季 Boardwalk Empire Season 1 (2010) 本季看点:1920年,联邦政府颁布禁酒令后,公开售卖酒类商品成为一种违法行为.在新泽西州的西南部的大西洋城没有任何 ...

  7. Kendall Rank(肯德尔等级)相关系数

    1.简介在统计学中,肯德尔相关系数是以Maurice Kendall命名的,并经常用希腊字母τ(tau)表示其值.肯德尔相关系数是一个用来测量两个随机变量相关性的统计值.一个肯德尔检验是一个无参数假设 ...

  8. Protobuf 协议语言指南

    l  定义一个消息(message)类型 l  标量值类型 l  Optional 的字段及默认值 l  枚举 l  使用其他消息类型 l  嵌套类型 l  更新一个消息类型 l  扩展 l  包(p ...

  9. git如何上传所有的新文件 gitlab如何上传所有的新文件 git本地覆盖服务器 强制本地覆盖服务器

    原文地址:  https://blog.csdn.net/qq_28093585/article/details/78749153 目的描述:新建的git项目,项目中有许多要从本地上传到git仓库的新 ...

  10. 数据库实例: STOREBOOK > 数据文件/退回字段/重做日志组|管理员

    ylbtech-Oracle:数据库实例: STOREBOOK  > 数据文件/退回字段/重做日志组|管理员 数据文件/退回字段/重做日志组|管理员 1. 数据库实例: STOREBOOK  & ...