题解 | #明明的随机数#

明明的随机数

https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

import java.util.*;
import java.util.stream.Collectors;


// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
    //     Scanner in = new Scanner(System.in);
    //     // 注意 hasNext 和 hasNextLine 的区别
    //     List<Integer> list = new ArrayList<>();
    //     in.nextInt();
    //     while (in.hasNextInt()) { // 注意 while 处理多个 case
    //         int a = in.nextInt();
    //     list.add(a);
    //     }
    //    list = list.stream().distinct().sorted((a,b)->a-b>0?1:-1).collect(
    //     Collectors.toList()
    //    );
       
    //    list.forEach(num->System.out.println(num));

    // 使用TreeSet
//     Scanner in = new Scanner(System.in);
//    TreeSet<Integer> set = new TreeSet<>();
//    in.nextInt();
//    while(in.hasNext()){
//     set.add(in.nextInt());
//    }
//    set.forEach(num->System.out.println(num));

// 使用bitmap
Scanner in = new Scanner(System.in);
in.nextInt();
int[] nums = new int[501];
while(in.hasNext()){
   Integer num =  in.nextInt();
        nums[num] = num;
}
for(int i = 0;i<501;i++){
    if(nums[i]!=0)
    System.out.println(nums[i]);
}

    }

}

全部评论

相关推荐

UtopianYou...:这个简历排版真的不太行哦,去找免费的或者花点小钱,把排版弄整齐一点吧,看着舒服。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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