题目描述:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", th...
分类:
编程语言 时间:
2015-11-03 22:42:46
阅读次数:
183
题意: 产生n对合法括号的所有组合,用vector返回。思路: 递归和迭代都可以产生。复杂度都可以为O(2n*合法的括号组合数),即每次产生出的括号序列都保证是合法的。 方法都是差不多的,就是记录当前产生的串中含有左括号的个数cnt,如果出现右括号,就将cnt--。当长度为2*n的串的cnt为...
分类:
其他好文 时间:
2015-10-31 23:07:52
阅读次数:
446
Given a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest...
分类:
其他好文 时间:
2015-10-31 14:19:03
阅读次数:
109
Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))...
分类:
其他好文 时间:
2015-10-30 07:06:46
阅读次数:
174
原题链接在这里:https://leetcode.com/problems/different-ways-to-add-parentheses/每当遇到运算符时,递归求运算符左侧的string 得到的list, 和 右侧string 得到的list, 然后根据运算符做运算,挨个放到res中。设a为操...
分类:
其他好文 时间:
2015-10-29 06:15:34
阅读次数:
194
Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct ...
分类:
其他好文 时间:
2015-10-23 11:56:33
阅读次数:
145
将所有合法的括号即一对()都消除,用桟保存其中不合法的括号即单个(或)在字符串中的下标。那么每两个不合法之间的下标之差减1就是中间的合法串长度,依次从后向前比较,选出最大的字符串。 1 class Solution { 2 public: 3 int longestValidParenthe...
分类:
其他好文 时间:
2015-10-23 10:16:43
阅读次数:
135
Implement a basic calculator to evaluate a simple expression string.The expression string may contain open(and closing parentheses), the plus+or minus...
分类:
其他好文 时间:
2015-10-21 23:57:07
阅读次数:
361
QuestionGivennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is...
分类:
其他好文 时间:
2015-10-18 06:32:52
阅读次数:
155
题意: 匹配括号,看是否所有括号都匹配。分析: 空行的时候要输出yes,其它的用栈正常做就行。代码: #include #include #include #include #include using namespace std;bool judge(char a,char b){ i...
分类:
其他好文 时间:
2015-10-15 14:15:14
阅读次数:
301