标签:blog div math idp == stack string val empty
class Solution { public int longestValidParentheses(String s) { int left=-1; Stack<Integer> stack=new Stack<Integer>(); int ret=0; for(int i=0;i<s.length();i++) { if(s.charAt(i)==‘(‘) stack.push(i); else { if(stack.isEmpty())left=i; else { stack.pop(); if(stack.isEmpty()) ret=Math.max(ret, i-left); else ret=Math.max(ret, i-stack.peek()); } } } return ret; } }
标签:blog div math idp == stack string val empty
原文地址:http://www.cnblogs.com/asuran/p/7580751.html