第一题AC了,第二题不会做 import java.util.*; public class NO1 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); Map<String,Integer> map = new HashMap<>(); map.put("()", 1); int result = helper(s,map); System.out.println(result); } public static int helper(String s , Map<String,Integer> map){ if(map.containsKey(s)){ return map.get(s); } int count = 0; int result = 0; for(int i = 0 ; i < s.length(); i ++){ if(s.charAt(i) == '('){ count++; }else{ count--; } if(count >= 0 && s.charAt(i) == ')'){ String left = s.substring(1,i); String right = s.substring(i+1,s.length()); result+= helper(left+right,map); } } map.put(s,result); return result; } }
点赞 1

相关推荐

牛客21331815...:像我一投就pass,根本不用焦虑泡池子
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务