解题思路: 从左往右依次判断,判断每一种情况
注意事项:
参考代码:
import java.util.*; public class Main { static String[] arr; static int x = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); arr = s.split(""); System.out.println(digui(0,0)); } private static int digui(int j, int a) { for(int i = j; i < arr.length; i++) { if(arr[i].equals("x")) { a += 1; }else if(arr[i].equals("(")){ a += digui(i+1,0); i = x; }else if(arr[i].equals(")")) { x = i; return a; }else if(arr[i].equals("|")) { return Math.max(a, digui(i+1,0)); } } return a; } }
0.0分
2 人评分