Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 543 Bytes

Question_1394.md

File metadata and controls

26 lines (21 loc) · 543 Bytes

LeetCode Records - Question 1394 Find Lucky Integer in an Array

Attempt 1: Use an int[] to save the frequencies of numbers

class Solution {
    public int findLucky(int[] arr) {
        int[] nums = new int[501];

        for (int num : arr) {
            nums[num]++;
        }

        for (int i = 500; i >= 1; i--) {
            if (nums[i] == i) {
                return i;
            }
        }

        return -1;
    }
}
  • Runtime: 1 ms (Beats: 100.00%)
  • Memory: 42.92 MB (Beats: 78.34%)