1 class Solution: 2 def findLucky(self, arr: List[int]) -> int: 3 dic = dict() 4 n = len(arr) 5 for i in range(n): 6 if arr[i] not in dic: 7 dic[arr[i]] = 1 8 else: 9 dic[arr[i]] += 1 10 maxnum = -1 11 for k,v in dic.items(): 12 if k == v and v > maxnum: 13 maxnum = v 14 return maxnum
算法思路:hash