CCF 考试,一定要刷历年真题。
在提交代码的时候,一定不要把中文注释提交上去了,可能会编译报错
- 题目描述
201312-1出现次数最多的数
- Java题解
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
/**
*
* @author wangdong
*
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
scanner.nextLine();
String str = scanner.nextLine();
scanner.close();
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(num);
String[] numsStrings = str.split(" ");
for (int i = 0; i < num; i++) {
Integer keyInteger = Integer.valueOf(numsStrings[i]);
if (map.containsKey(keyInteger)) {
Integer tar = map.get(keyInteger);
map.put((keyInteger), map.ge