JAVA_LeetCode 1394_Find Lucky Integer in an Array


JAVA_LeetCode 1394_Find Lucky Integer in an Array

JAVA_LeetCode 1394_Find Lucky Integer in an Array 풀이 class Solution { public int findLucky(int[] arr) { // hashmap의 key-value, getOrDefault 메서드를 사용한다. int max = -1; HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < arr.length; i++){ map.put(arr[i], map.getOrDefault(arr[i], 0) + 1); } for (int i : map.keySet()){ if (map.get(i) == i) max = Math.max(max, i); } return max; } } hashmap의 getOrDefault를 이용하여 키, 값을 설정한다. * 출처 https://leetcode.com/problems/find-lucky-integer-in-an-array...


#JAVA #JAVA_FindLuckyIntegerinanArray #JAVA_LeetCode1394 #JAVA_LeetCode1394_FindLuckyIntegerinanArray #LeetCode1394_FindLuckyIntegerinanArray

원문링크 : JAVA_LeetCode 1394_Find Lucky Integer in an Array