猿辅导22号笔试第一题

有没有大佬帮忙看下代码哪里有问题,一直是0%。

// 第一题
public class YuanFuDao {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int  n = sc.nextInt();
        int[] tree = new int[n];
        for (int i = 0; i<n; i++){
            tree[i] = sc.nextInt();
        }
        List<Integer> list  = new ArrayList<>();
        list.add(tree[0]);
        // 左边界
        int index = 0;
        while (2 * index + 1 < n) {
            list.add(tree[2 * index + 1]);
            index = 2 * index + 1;
        }
        // 下层边界
        int left = index;
        index += 1;
        for (; index < n; index ++){
            list.add(tree[index]);
        }
        // 次下层边界
        index = (index-2)/2 + 1;
        while (index < left){
            list.add(tree[index]);
            index++;
        }
        // 右边界
        index = 0;
        while (2 * index + 2 < n) {
            list.add(tree[2 * index + 2]);
            index = 2 * index + 2;
        }

        StringBuilder sb = new StringBuilder();
        int i = 0;
        for (; i<list.size()-2; i++){
            sb.append(list.get(i));
            sb.append(' ');
        }
        sb.append(list.get(i));
        System.out.println(sb.toString());
    }
}


#猿辅导##笔试题目#
全部评论
我知道了,右边界没有倒序😭
点赞 回复 分享
发布于 2020-08-22 20:55

相关推荐

不愿透露姓名的神秘牛友
07-16 12:18
点赞 评论 收藏
分享
06-12 16:00
天津大学 Java
牛客30236098...:腾讯坏事做尽,终面挂是最破防的 上次被挂了后我连简历都不刷了
点赞 评论 收藏
分享
07-11 22:27
中南大学 Java
程序员牛肉:学历的话没问题。但是没问题的也就只有学历了。 其实你的整体架构是正确的,博客接着干。但是项目有点过于简单了。从后端的角度上讲,你这也就是刚入门的水平,所以肯定约面试够呛。 如果你要应聘后端岗位,那你第一个项目竟然是仿写操作系统。这个你要面试官咋问你。你一定要记住一点,你简历上写的所有的东西,都是为了证明你有能力胜任当前的岗位,而不是为了证明你自己会什么。 如果你只是浅浅的做几个项目,描述也都是烂大街。技术点也都是各种混水类的配置类需求,那你就不要幻想自己能走多远。一定要保持思考,保持学习。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务