My LeetCode grinding. Trying to do a problem a day.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536
  1. Given an array of integers arr, a lucky integer is an integer which has a frequency in the array equal to its value.
  2. Return a lucky integer in the array. If there are multiple lucky integers return the largest of them. If there is no lucky integer return -1.
  3. Example 1:
  4. Input: arr = [2,2,3,4]
  5. Output: 2
  6. Explanation: The only lucky number in the array is 2 because frequency[2] == 2.
  7. Example 2:
  8. Input: arr = [1,2,2,3,3,3]
  9. Output: 3
  10. Explanation: 1, 2 and 3 are all lucky numbers, return the largest of them.
  11. Example 3:
  12. Input: arr = [2,2,2,3,3]
  13. Output: -1
  14. Explanation: There are no lucky numbers in the array.
  15. Example 4:
  16. Input: arr = [5]
  17. Output: -1
  18. Example 5:
  19. Input: arr = [7,7,7,7,7,7,7]
  20. Output: 7
  21. Constraints:
  22. 1 <= arr.length <= 500
  23. 1 <= arr[i] <= 500