This commit is contained in:
parent
846f489d7b
commit
39eb343d8c
1 changed files with 10 additions and 0 deletions
10
easy/kth_distinct_string_in_an_array.py
Normal file
10
easy/kth_distinct_string_in_an_array.py
Normal 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]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue