-1
로 설정arr
순회하며 숫자 빈도 확인function findLucky(arr: number[]): number {
let maxLuckyNum = -1
const frequent = new Map()
for(const num of arr) frequent.set(num, (frequent.get(num) ?? 0) + 1)
for(const [key, value] of frequent) {
if(key !== value) continue
maxLuckyNum = Math.max(maxLuckyNum, key)
}
return maxLuckyNum
};