DescriptionParentheses BalanceYou are given a string consisting of parentheses()and[]. A string of this type is said to becorrect:(a)if it is the empt...
分类:
其他好文 时间:
2015-01-26 22:18:59
阅读次数:
145
题目:
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
"((()))", "(()())", "(())()", "()(()...
分类:
其他好文 时间:
2015-01-25 21:05:00
阅读次数:
171
题目:
Given a string containing just the characters '(', ')', '{', '}', '[' and ']',
determine if the input string is valid.
The brackets must close in the correct order, "()" and "()[]{}" are...
分类:
其他好文 时间:
2015-01-25 16:44:04
阅读次数:
136
原题地址《Cracking the Code》一书中出现过这道题,那里面提到了多种解法,这里用最简单的枚举法。DFS枚举,令leftRemain表示当前还剩下几个"("可用,rightRemain表示当前还剩下几个")"可用。如果leftRemain > 0,那么总可以放一个"("如果leftRem...
分类:
其他好文 时间:
2015-01-25 15:01:15
阅读次数:
181
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'20: Valid Parentheseshttps://oj.leetcode.com/problems/valid-parentheses/Given a string con...
分类:
编程语言 时间:
2015-01-24 00:21:16
阅读次数:
364
【题目】
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
"((()))", "(()())", "(())()", "()((...
分类:
其他好文 时间:
2015-01-23 23:03:25
阅读次数:
214
【题目】
Given a string containing just the characters '(', ')', '{', '}', '[' and ']',
determine if the input string is valid.
The brackets must close in the correct order, "()" and "()[]{}" ar...
分类:
其他好文 时间:
2015-01-23 21:34:47
阅读次数:
181
题意 判断输入的括号序列是否是配对的
栈的基础应用 栈顶元素与输入的字符匹配就出栈咯 注意括号序列可以为空
STL栈
#include
using namespace std;
int main()
{
int cas;
char c;
cin >> cas;
getchar();
while(cas--)
{
stac...
分类:
其他好文 时间:
2015-01-23 18:26:16
阅读次数:
192
原题链接:https://oj.leetcode.com/problems/valid-parentheses/
检查是否是有效的括号序列。这里的解法是维护一个栈,如果是左括号,则push到栈中,如果是右括号,则检查栈顶的符号,如果是对应的做括号,则将之弹出。否则,则直接返回false。当字符串扫描到尾时,则检查栈是否是空,如果是空,则说明所有的括号都match上了。
clas...
分类:
其他好文 时间:
2015-01-23 16:30:25
阅读次数:
178
原题地址方法I:动态规划len[i]表示从i开始到结束的最长合法括号串长度,则:如果s[i] == "(" 且 s[i+len[i+1]+1]==")",len[i] = len[i+1] + 2否则len[i] = 0方法II:辅助栈跟那个直方图求最大面积有点类似,用一个栈保存合法括号串的长度,显...
分类:
其他好文 时间:
2015-01-23 06:10:15
阅读次数:
138