fork download
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. import java.util.OptionalInt;
  4. import java.util.stream.IntStream;
  5.  
  6. public class Ar2 {
  7. public static void main(String[] args) {
  8. Scanner sc = new Scanner(System.in);
  9. int[] votes = new int[sc.nextInt()];
  10. Arrays.fill(votes, 0);
  11. int M = sc.nextInt();
  12. for (int i = 0; i < M; i++) {
  13. votes[sc.nextInt()] += 1;
  14. }
  15. int maxVotes = Arrays.stream(votes).max().getAsInt();
  16. int candidate = 0;
  17. int maxCandidate;
  18. while (true) {
  19. maxCandidate = votes[candidate];
  20. if (maxVotes == maxCandidate) {
  21. System.out.println(candidate);
  22. break;
  23. }
  24. candidate++;
  25. }
  26. }
  27. }
  28.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5 4
1
2
3
3
compilation info
Main.java:6: error: class Ar2 is public, should be declared in a file named Ar2.java
public class Ar2 {
       ^
1 error
stdout
Standard output is empty