想着用动态规划的方法,有点类似于n*n的网格,从(0,0)开始走到(n-1,n-1)有几种方法。当然必须满足纵坐标大于等于横坐标,还有必须记录到达每一个点所走的方法(这里指的是有多少不同的字符串)。 class Solution { public: vector<string> generatePa ...
分类:
其他好文 时间:
2016-04-10 20:58:31
阅读次数:
166
因为要算匹配长度,所以要记录起始的位置。思路上要分三种情况吧,一种是完全匹配,一种是未匹配的是‘)’,一种是未匹配的是‘(’。如果发现没有左括号可以和右括号匹配,那么只要把右括号位置设置为start,重新开始新一轮的寻找就可以了;如果没有右括号可以和左括号匹配,则要用当前位置减去堆栈栈顶的左括号位置 ...
分类:
其他好文 时间:
2016-04-10 12:42:46
阅读次数:
216
这题不能使用递归来写,因为有一个输入长度是17173,会爆栈。因此得手动模拟栈调用。 ...
分类:
其他好文 时间:
2016-04-10 01:01:45
阅读次数:
110
题目:
Given a string containing just the characters , determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but “(]” and “([)]” are not.翻译:...
分类:
其他好文 时间:
2016-03-24 14:49:05
阅读次数:
135
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Given n = 3, a solution set is: "((()))", "(()
分类:
其他好文 时间:
2016-03-21 09:22:49
阅读次数:
188
241. Different Ways to Add Parentheses https://leetcode.com/problems/different-ways-to-add-parentheses/ 思路就是:首先找到以运算符为根节点,分别计算左子串和右子串的所有结果的集合,然后依次进行组合
分类:
其他好文 时间:
2016-03-19 22:46:28
阅读次数:
166
判断括号是否合法 1.用stack存入左括号“([{”,遇到相应的右括号“)]}”就退栈 2.判断stack是否为空,可以判断是否合法
分类:
其他好文 时间:
2016-03-16 20:44:38
阅读次数:
109
题目描述: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set
分类:
其他好文 时间:
2016-03-09 00:06:15
阅读次数:
258
There’s an even simpler way to include values in strings: Write the value in parentheses, and write a backslash (\) before the parentheses. This is kn
分类:
编程语言 时间:
2016-03-08 14:56:58
阅读次数:
163