-
[프로그래머스]모의고사Coding 2021. 6. 29. 21:01
* 알게된점
1.TreeMap의 경우 가장 큰 키를 반환하는 메소드가 존재함
- lastkey()
-그 이외에 higerKey(K key), floorkey(K key), ceilingKey(K key), firstKey() 존재함
2. 다른 사람 풀이 중 3가지 숫자의 max값을 구하는 방법
int max = Math.max(hit[0], Math.max(hit[1], hit[2]));
TreeMap<Integer, List<Integer>> map = new TreeMap<>(); int[][] players = { { 1, 2, 3, 4, 5 }, { 2, 1, 2, 3, 2, 4, 2, 5 }, { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 } }; int arr_length; for (int i = 0; i < players.length; i++) { int sum = 0; arr_length = players[i].length; for (int j = 0; j < answers.length; j++) { if (answers[j] == players[i][j % arr_length]) { sum++; } } if (map.containsKey(sum)) { map.get(sum).add(i + 1); } else { map.put(sum, new LinkedList<>(Arrays.asList(i + 1))); } } return map.get(map.lastKey()).stream().mapToInt((s) -> s.intValue()).toArray();
'Coding' 카테고리의 다른 글
Deque<E>을 Stack처럼 사용 시 주의 사항 (0) 2021.07.11 문자열 안에 숫자가 있는지 확인 할 때..match사용 (0) 2021.07.04 [프로그래머스] 이중우선순위 큐 (0) 2021.06.25 [프로그래머스] 디스크 컨트롤러 (0) 2021.06.20 [프로그래머스]프린터 (0) 2021.06.18