結果

問題 No.79 過小評価ダメ・ゼッタイ
ユーザー yagi2
提出日時 2017-04-25 14:37:34
言語 Java
(openjdk 23)
結果
AC  
実行時間 488 ms / 5,000 ms
コード長 940 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 89,176 KB
実行使用メモリ 48,244 KB
最終ジャッジ日時 2024-06-26 08:12:19
合計ジャッジ時間 9,714 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());

        Map<Integer, Integer> L = new HashMap<>();
        for (int i = 0 ; i < N; i++) {
            int l = Integer.parseInt(sc.next());

            if (!L.containsKey(l)) L.put(l, 0);
            L.put(l, L.get(l)+1);
        }

        List<Map.Entry<Integer, Integer>> entryList = new ArrayList<>(L.entrySet());
        entryList.sort((o1, o2) -> {
            if (o1.getValue() > o2.getValue()) return -1;
            if (o1.getValue() < o2.getValue()) return 1;

            if (Objects.equals(o1.getValue(), o2.getValue())) {
                if (o1.getKey() > o2.getKey()) return -1;
                if (o1.getKey() < o2.getKey()) return 1;
            }
            return 0;
        });

        System.out.println(entryList.get(0).getKey());
    }
}
0