首页 > 跟谁学提前批8.7算法笔试编程题(已挂,浪费时间)
头像
最爱数学的人
编辑于 2020-08-21 17:16
+ 关注

跟谁学提前批8.7算法笔试编程题(已挂,浪费时间)

很迷的题 没有调试评分机制
    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) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐