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. unlocked_ioctl和compat_ioctl

    参考: https://www.cnblogs.com/super119/archive/2012/12/03/2799967.html https://lwn.net/Articles/119652 ...

  2. Android如何运行真机在eclipse上调试应用?

    主要通过以下几个步骤: 1.手机通过数据线连接在电脑上 2.设置android手机为USB调试模式.步骤: menu—> 设置 —> 应用程序 —> 开发 , 选择[USB调试] 3 ...

  3. Maven 使用了一个标准的目录结构和一个默认的构建生命周期。

    Maven 使用了一个标准的目录结构和一个默认的构建生命周期. 约定优于配置 当创建 Maven 工程时,Maven 会创建默认的工程结构.开发者只需要合理的放置文件,而在 pom.xml 中不再需要 ...

  4. WordPress主题开发:优化标题

    页面使用: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

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

    英文全名Agents Of SHIELD,第4季(2016)ABC. 本季看点:<神盾局特工>(Agents Of SHIELD)第三季季终集里,我们终于知道谁死了……但死的不是一个,而是 ...

  6. mysql处理特殊字符

    修改表 alter table USER convert to charset utf8mb4, character set utf8mb4; 修改列 ALTER TABLE USER DEFAULT ...

  7. AppStore中使用IDFA后提交应用的注意事项

    在ios7.0出来以前,我们都是通过wifi的mac来当作IOS设备的唯一标识符.如何在ios下获取设备的MAC,你可以参数这篇文章:获取ios的MAC地址 在没有使用IDFA之前,我们在ios7及以 ...

  8. Android Studio 下载地址

    下载地址:https://developer.android.com/sdk/index.html#download      这个网址可以下载需要的东西,FQ的话可以给 xifulinmen@gma ...

  9. [Web 前端] 前端频道之团队维护、聚合、订阅

    cp from :https://blog.csdn.net/ivan820819/article/details/78885404 国内 腾讯 ISUX 腾讯全端 AlloyTeam 奇舞周刊 阿里 ...

  10. 深入理解多线程(四)—— Moniter的实现原理

    在深入理解多线程(一)——Synchronized的实现原理中介绍过关于Synchronize的实现原理,无论是同步方法还是同步代码块,无论是ACC_SYNCHRONIZED还是monitorente ...