bumpsoo 2024-08-05 22:14:11 +09:00
parent 846f489d7b
commit 39eb343d8c

View file

@ -0,0 +1,10 @@
# https://leetcode.com/problems/kth-distinct-string-in-an-array
from typing import List
class Solution:
def kthDistinct(self, arr: List[str], k: int) -> str:
cnt = dict()
for i in range(len(arr)):
cnt[arr[i]] = len(arr) if arr[i] in cnt else i
ret = sorted(cnt.values())[k - 1] if 0 <= k - 1 < len(cnt) else -1
return "" if ret < 0 or ret >= len(arr) else arr[ret]