File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,276 LeetCode solutions in JavaScript
1
+ # 1,277 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1063
1063
1390|[ Four Divisors] ( ./solutions/1390-four-divisors.js ) |Medium|
1064
1064
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|
1065
1065
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|
1066
1067
1400|[ Construct K Palindrome Strings] ( ./solutions/1400-construct-k-palindrome-strings.js ) |Medium|
1067
1068
1402|[ Reducing Dishes] ( ./solutions/1402-reducing-dishes.js ) |Hard|
1068
1069
1408|[ String Matching in an Array] ( ./solutions/1408-string-matching-in-an-array.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments