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 ...
随机推荐
- centOS下lnamp安装
首先安装apache,mysql ,最后安装php 1>apache安装 安装:yum install -y httpd 运行:/bin/systemctl start httpd.servic ...
- 【windows】共享文件夹设置
控制面板\网络和 Internet\网络和共享中心\高级共享设置 在当前的域\公用\家庭网络 下文件和打印机共享开关打开 现在可以在 计算机-网络 里面看到共享的计算机啦 选中自己想要分享的文件,右键 ...
- zoj 4054
#define ll long long ; int t; ll ans,tmp; char s[N]; int main() { scanf("%d",&t); whil ...
- ACM-ICPC 2016 Qingdao Preliminary Contest G. Sort
Recently, Bob has just learnt a naive sorting algorithm: merge sort. Now, Bob receives a task from A ...
- LAMP动态网站安装脚本
#!/bin/bash #auto make install LAMP #by authors zhangjianghua #httpd define path variable H_FILES=ht ...
- Java构造器(construtor)与垃圾收集器(GB)
在Java中,程序员会在乎内存中的两块空间. 堆(heap)和栈(stack). 当java虚拟机启动时, 它会从底层的操作系统取得一块内存, 并且以此块内存来执行java程序. 在Java中, 实例 ...
- UVa 11651 Krypton Number System DP + 矩阵快速幂
题意: 有一个\(base(2 \leq base \leq 6)\)进制系统,这里面的数都是整数,不含前导0,相邻两个数字不相同. 而且每个数字有一个得分\(score(1 \leq score \ ...
- asynctask 异步下载
public class MainActivity extends Activity{ private TextView show; @Override public void onCreate(Bu ...
- 国内外移动端web适配屏幕方案总结
基础知识点 设备像素:设备像素又称物理像素(physical pixel),设备能控制显示的最小单位,我们可以把这些像素看作成显示器上一个个的点. iPhone5的物理像素是640X1136. PS: ...
- Spring Cloud(2.0)能力大致列表
微服务九大特性 出自Martin Fowler的<Microservices> 服务组件化 按业务组织团队 做"产品"的态度 智能端点与哑管道 去中心化治理 去中心化管 ...