32. Longest Valid Parentheses
来源:互联网 发布:cad2008批量打印软件 编辑:程序博客网 时间:2024/04/27 21:03
Longest Valid Parentheses
Given a string containing just the characters '('
and ')'
, find the length of the longest valid (well-formed) parentheses substring.
For "(()"
, the longest valid parentheses substring is "()"
, which has length = 2.
Another example is ")()())"
, where the longest valid parentheses substring is"()()"
, which has length = 4.
package leetcode;public class leet32 {public static void main(String[] args) {leet32 leet = new leet32();int result = leet.longestVaildParentheses("((())");System.out.println(result);}public int longestVaildParentheses(String s){StringBuilder str = new StringBuilder();for(int i = 0;i < s.length();i++){if(s.charAt(i) == '('){str.append(s.charAt(i));}else{if(str.length() == 0){str.append(s.charAt(i));}else if(str.substring(str.length()-1).equals("(")){String tmp = str.substring(0, str.length()-1);str = new StringBuilder().append(tmp);}else{str.append(s.charAt(i));}}}return s.length()-str.length();}}
0 0
- 32.Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 32. Longest Valid Parentheses
- 416. Partition Equal Subset Sum
- 观察者模式--C++
- 机器学习笔记 - 剪枝处理
- theano scan arange shape 实例
- 图像的基本运算
- 32. Longest Valid Parentheses
- pat 1122. Hamiltonian Cycle (25)
- github新建、删除项目,提交、删除文件
- 图的基本存储的基本方式二
- iOS UITextView 字数限制+提示剩余可输入字数
- Android 高效调试神器 JRebel
- python复习笔记[1]——语法和逻辑
- 读书笔记 effective c++ Item 11 在operator=中处理自我赋值
- 程序的机器级表示(二)