-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
42 lines (33 loc) · 1.13 KB
/
Main.java
File metadata and controls
42 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
public class Main {
public static void main(String[] args){
int[] nums = {3,2,4,4,2,5,2,5,5};
List<Integer> ans = new ArrayList<Integer>();
ans = Main.count(nums);
System.out.println(ans);
}
public static List count(int[] arr) {
if (arr == null || arr.length == 0) return new ArrayList<Integer>(Arrays.asList(-1));
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
List<Integer> ans = new ArrayList<Integer>();
// map 에 중복값 count
for(int i=0; i<arr.length; i++){
if(map.containsKey(arr[i])){
map.put(arr[i], map.get(arr[i])+1);
} else {
map.put(arr[i], 1);
}
}
Iterator<Integer> keys = map.keySet().iterator();
while(keys.hasNext()){
int answer = map.get(keys.next());
if(answer > 1) ans.add(answer);
}
return ans;
}
}