LintCode: Valid Parentheses
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的更多相关文章
- [LintCode] Valid Parentheses 验证括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- 423. Valid Parentheses【LintCode java】
Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine ...
- [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 ...
随机推荐
- 用C扩展Python3
官方文档: https://docs.python.org/3/extending/index.html 交叉编译到aarch64上面 以交叉编译到aarch64上面为例,下面是Extest.c的实现 ...
- javascript中{},[]中括号,大括号使用
一.{ } 大括号,表示定义一个对象,大部分情况下要有成对的属性和值,或是函数. 如:var LangShen = {"Name":"Langshen",&qu ...
- java ffmpeg视频转码(自测通过)
import java.io.*; public class VideoTransfer { //ffmepg文件 安装目录 private static String ffmpeg = " ...
- .Net Core中文编码问题整理
1..Net Core Console控制台程序 在.Net Core中默认System.Text中不支持CodePagesEncodingProvider.Instance, System.Text ...
- js转义和反转义html htmlencode htmldecode
文章目录 JS实现HTML标签转义及反转义 用Javascript进行HTML转义 1.HTML转义 2.反转义 3.一个有意思的认识 4.完整版本的代码 其他 [转义字符]HTML 字符实体< ...
- asp.net为什么会产生app_offline.htm 这个文件,为什么删除后运行浏览器就不会报应用程序脱机
一般是发布的时候自动生成的.VS2008在发布程序的时候,会首先在网站目录中生成这个文件,并把该虚拟目录的首页设成这个文件. 这样你在发布程序的时候如果有人访问网站就会看到这个页面. 不影响发布.ap ...
- 多线程学习-ListenableFuture使用介绍以及示例
Guava为Java并行编程Future提供了很多有用扩展,其主要接口为ListenableFuture,并借助于Futures静态扩展.ListenableFuture顾名思义就是可以监听的Futu ...
- go语言之进阶篇方法值
1.方法值 示例: package main import "fmt" type Person struct { name string //名字 sex byte //性别, 字 ...
- 技术向:一文读懂卷积神经网络CNN
转自:http://dataunion.org/11692.html 作者:张雨石 自今年七月份以来,一直在实验室负责卷积神经网络(Convolutional Neural Network,CNN), ...
- 记录Activity启动时间 ActivityLifecycleCallbacks
ActivityStackManager 定义一个集合(Stack)保存所有还未销毁的 Activity public class ActivityStackManager { private Sta ...