牛客网 俄罗斯方块

链接:https://www.nowcoder.com/questionTerminal/9407e24a70b04fedba4ab3bd3ae29704?source=relative
来源:牛客网

小易有一个古老的游戏机,上面有着经典的游戏俄罗斯方块。因为它比较古老,所以规则和一般的俄罗斯方块不同。
荧幕上一共有 n 列,每次都会有一个 1 x 1 的方块随机落下,在同一列中,后落下的方块会叠在先前的方块之上,当一整行方块都被占满时,这一行会被消去,并得到1分。
有一天,小易又开了一局游戏,当玩到第 m 个方块落下时他觉得太无聊就关掉了,小易希望你告诉他这局游戏他获得的分数。
输入描述:
第一行两个数 n, m
第二行 m 个数,c

1

, c

2

, ... , c

m

 , c

i

 表示第 i 个方块落在第几列
其中 1 <= n, m <= 1000, 1 <= c

i

 <= n


输出描述:
小易这局游戏获得的分数
示例1

输入

3 9
1 1 2 2 2 3 1 2 3

输出

2


import java.util.*;
public class Main {
    public static void main(String[] args) {
        System.out.println(grade());


    }
    public static int grade(){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] array = new int[n];
        for(int i = 0;i < m;i++){
            array[scanner.nextInt()-1]++;
        }
        Arrays.sort(array);
        return array[0];

    }

}
原文地址:https://www.cnblogs.com/hetaoyuan/p/11335102.html