欢迎光临散文网 会员登陆 & 注册

leetcode 1394. Find Lucky Integer in an Array

2022-02-10 18:26 作者:您是打尖儿还是住店呢  | 我要投稿

Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value.

Return the largest lucky integer in the array. If there is no lucky integer return -1.

 

Example 1:

Input: arr = [2,2,3,4]Output: 2Explanation: The only lucky number in the array is 2 because frequency[2] == 2.

Example 2:

Input: arr = [1,2,2,3,3,3]Output: 3Explanation: 1, 2 and 3 are all lucky numbers, return the largest of them.

Example 3:

Input: arr = [2,2,2,3,3]Output: -1Explanation: There are no lucky numbers in the array.




Runtime: 10 ms, faster than 13.49% of Java online submissions for Find Lucky Integer in an Array.

Memory Usage: 43.6 MB, less than 11.76% of Java online submissions for Find Lucky Integer in an Array.


leetcode 1394. Find Lucky Integer in an Array的评论 (共 条)

分享到微博请遵守国家法律