很迷的题 没有调试评分机制
static void print_dual_char_words(String[] x, int N) { for (String str : x) { if (isValid(str)) { System.out.println(str); } } } static boolean isValid(String str) { HashSet<Character> visited = new HashSet<>(); HashSet<Character> set = new HashSet<>(); for (int i = 0; i < str.length(); i++) { if (!set.contains(str.charAt(i))) { if (visited.contains(str.charAt(i))) return false; set.add(str.charAt(i)); } else { set.remove(str.charAt(i)); } visited.add(str.charAt(i)); } return set.isEmpty(); }
static int num_bets_before_game_over(int N) { Random random = new Random(); long total = 0; for (int i = 0; i < 100000; i++) { int cur = N; long temp = 0; while (cur > 0 && cur < 2*N) { boolean b = random.nextBoolean(); if (b) cur++; else cur--; temp++; } total += temp; } // System.out.println((double)total/100000); return (int)((double)total/100000+0.5); }
8.21更新 笔试挂 看不懂 你还不如不要笔试 浪费时间
全部评论
(1) 回帖