Skip to content

Commit eb3f5b0

Browse files
committedApr 13, 2025
Add solution #1394
1 parent ca534db commit eb3f5b0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,276 LeetCode solutions in JavaScript
1+
# 1,277 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1063,6 +1063,7 @@
10631063
1390|[Four Divisors](./solutions/1390-four-divisors.js)|Medium|
10641064
1391|[Check if There is a Valid Path in a Grid](./solutions/1391-check-if-there-is-a-valid-path-in-a-grid.js)|Medium|
10651065
1392|[Longest Happy Prefix](./solutions/1392-longest-happy-prefix.js)|Hard|
1066+
1394|[Find Lucky Integer in an Array](./solutions/1394-find-lucky-integer-in-an-array.js)|Easy|
10661067
1400|[Construct K Palindrome Strings](./solutions/1400-construct-k-palindrome-strings.js)|Medium|
10671068
1402|[Reducing Dishes](./solutions/1402-reducing-dishes.js)|Hard|
10681069
1408|[String Matching in an Array](./solutions/1408-string-matching-in-an-array.js)|Easy|
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 1394. Find Lucky Integer in an Array
3+
* https://leetcode.com/problems/find-lucky-integer-in-an-array/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of integers arr, a lucky integer is an integer that has a frequency
7+
* in the array equal to its value.
8+
*
9+
* Return the largest lucky integer in the array. If there is no lucky integer return -1.
10+
*/
11+
12+
/**
13+
* @param {number[]} arr
14+
* @return {number}
15+
*/
16+
var findLucky = function(arr) {
17+
const frequencyMap = new Map();
18+
let result = -1;
19+
20+
for (const num of arr) {
21+
frequencyMap.set(num, (frequencyMap.get(num) || 0) + 1);
22+
}
23+
for (const [num, count] of frequencyMap) {
24+
if (num === count && num > result) {
25+
result = num;
26+
}
27+
}
28+
29+
return result;
30+
};

0 commit comments

Comments
 (0)
Please sign in to comment.