import java.util.Scanner; import java.util.Stack; public class Main {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         String str_brackets = sc.nextLine();         char[] brackets = str_brackets.toCharArray();         Stack<Integer> stack = new Stack<Integer>();         stack.push(-1);         int max_valid_len = 0;         for(int i = 0; i<brackets.length; i++) {             int temp = stack.peek();             if((temp!=-1) && (brackets[i]==')') && (brackets[temp]=='(')) {                 stack.pop();                 max_valid_len = Math.max(max_valid_len,i-stack.peek());             }else {                 stack.push(i);             }         }         System.out.println(max_valid_len);              } }
点赞 3

相关推荐

10-28 14:42
门头沟学院 Java
watermelon1124:因为嵌入式炸了
点赞 评论 收藏
分享
09-27 10:54
重庆大学 C++
人已微死:致敬传奇耐测王。
投递小米集团等公司10个岗位
点赞 评论 收藏
分享
牛客网
牛客企业服务