LeetCode OJ——Longest Valid Parentheses
http://oj.leetcode.com/problems/longest-valid-parentheses/
最大括号匹配长度,括号是可以嵌套的
#include <string>
#include <stack>
#include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
int longestValidParentheses(string s) {
const int s_len = s.size(); stack<int> indexstack;
vector<bool> flagvector;
int templen = ;
int maxlen = ;
flagvector.resize(s_len); for(int index = ;index<s_len;index++)
flagvector[index] = false; for(int i = ;i<s_len;i++)
{
if(s[i]==')')
{
if(indexstack.size()!=)
{
flagvector[indexstack.top()] = true;
flagvector[i] = true;
indexstack.pop();
} }
if(s[i]=='(')
{
indexstack.push(i);
}
}
for(int index = ;index<s_len;index++)
{
if(flagvector[index]==false)
{
maxlen = maxlen>templen?maxlen:templen;
templen = ;
}
else
templen++;
}
maxlen = maxlen>templen?maxlen:templen;
return maxlen;
}
};
#include <iostream>
#include "cla.h"
using namespace std;
int main()
{
Solution * mysolution = new Solution();
string str = "";
cout<<mysolution->longestValidParentheses(str)<<endl;
return ;
}
LeetCode OJ——Longest Valid Parentheses的更多相关文章
- [LeetCode] 032. Longest Valid Parentheses (Hard) (C++)
指数:[LeetCode] Leetcode 指标解释 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 032. Lon ...
- Java for LeetCode 032 Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- LeetCode 之 Longest Valid Parentheses(栈)
[问题描写叙述] Given a string containing just the characters '(' and ')', find the length of the longest v ...
- [LeetCode] 32. Longest Valid Parentheses 最长有效括号
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
- 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 ...
- Java [leetcode 32]Longest Valid Parentheses
题目描述: Given a string containing just the characters '(' and ')', find the length of the longest vali ...
- [leetcode]32. Longest Valid Parentheses最长合法括号子串
Given a string containing just the characters '(' and ')', find the length of the longest valid (wel ...
随机推荐
- 【线段树 泰勒展开】Codechef April Challenge 2018 Chef at the Food Fair
第一次写泰勒展开:本地和CC差距好大 题目大意 大厨住的城市里办了一场美食节.一条街上开设了$N$个摊位,编号为$1∼N$.这天开始时,第$i$个摊位的食物会导致食物中毒的概率是$P_i$.在这一天中 ...
- linux文件属性文文件类型知识
文件类型分别介绍: 1.普通文件:我们通过用ls -l来查看xxx.sql的属性,可以看到第一列内容为-rw-r--r--,值得注意的是第一个符号是-(英文字符减号),在Linux中,以这样的字符开 ...
- http客户端与浏览器的区别
两者区别:浏览器对http响应头会进行特定处理(如自动读取本地缓存.设置cookie等),而http客户端(如crul)可能没有像浏览器那样的处理,某些封装程度高的http客户端,可能会有. 同一个文 ...
- thinkcmf常用标签
1.图片地址:{:cmf_get_image_url($vo.icon)} 2.模板控件 模板变量调用:$theme_vars.title <widget name="aboutUs& ...
- redis列表,字典,管道,vue安装,创建项目
redis mysql,redis,mogondb 1.mysql,oracle:关系型数据库,有表概念 2.redis,mongodb/nosql:非关系型数据库 没有表概念 mongodb存储在硬 ...
- perl-basic-分支&循环
if elsif shorter if: if+condition放在句子尾部. use strict; use warnings; my $word = "antidisestablish ...
- leetcode-11-dfs
DFS算法: explore(G, v) visited(v) = trueprevisit(v) for each edge(v, u) in E: if not visited(u): explo ...
- [转] sublime插件
Sublime Text 系列 Sublime Text:学习资源篇 Sublime插件:增强篇 Sublime插件:Markdown篇 Sublime插件:C语言篇 Sublime插件:主题篇 Su ...
- luogu2158 [SDOI2008]仪仗队 欧拉函数
点 $ (i,j) $ 会看不见当有 $ k|i $ 且 $ k|j$ 时. 然后就成了求欧拉函数了. #include <iostream> #include <cstring&g ...
- luogu3388 【模板】割点(割顶)
模板题 #include <iostream> #include <cstdio> using namespace std; struct Edge{ int too, nxt ...