Skip to content

Commit dd4e7f3

Browse files
committed
💚Upload 1394 Code
💚Upload 1394 Code
1 parent 7379dc2 commit dd4e7f3

File tree

1 file changed

+17
-0
lines changed
  • solutions/1394-Find-Lucky-Integer-in-an-Array

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import List
2+
import collections
3+
4+
class Solution:
5+
def findLucky(self, arr: List[int]) -> int:
6+
cnt = collections.Counter(arr)
7+
# 先按频次排序,再按数值大小排序
8+
res = sorted(cnt.items(), key=lambda x:(x[1],x[0]), reverse=True)
9+
for i in range(len(res)):
10+
# 频次等于数值大小
11+
if res[i][0] == res[i][1]:
12+
return res[i][0]
13+
return -1
14+
15+
if __name__ == "__main__":
16+
arr = [2,2,3]
17+
print(Solution().findLucky(arr))

0 commit comments

Comments
 (0)