32.|32. Longest Valid Parentheses
https://leetcode.com/problems/longest-valid-parentheses/description/
解题思路:用stack来解决
class Solution {
public int longestValidParentheses(String s) {
Stack stack = new Stack();
int res = 0;
int count = 0;
for (int i = 0 ;
i < s.length();
i++){
if(s.charAt(i)=='('){
stack.push(count);
count = 0;
}else{
if(!stack.isEmpty()){
count = count + 1 + stack.peek();
stack.pop();
res = Math.max(res, count);
}else{
count = 0;
}
}
}
return res*2;
}
【32.|32. Longest Valid Parentheses】}
推荐阅读
- 解决SyntaxError:|解决SyntaxError: invalid syntax
- LeetCode(03)Longest|LeetCode(03)Longest Substring Without Repeating Characters
- cannot|cannot be read or is not a valid ZIP file
- mac升级之(xcrun:|mac升级之:xcrun: error: invalid active developer path, missing xcrun)
- element-ui表单验证例子(validateField验证部分表单)
- 寻找写代码感觉(十六)之|寻找写代码感觉(十六)之 集成Validation做参数校验
- Unable|Unable to add window -- token null is not valid; is your activity running?
- RpcException:|RpcException: Invalid token! Failed to invoke method
- 解决vue项目中的“Invalid|解决vue项目中的“Invalid Host header”
- python|leetcode Longest Substring with At Most Two Distinct Characters 滑动窗口法