Skip to content

Commit f9a8a72

Browse files
authored
Create kth-distinct-string-in-an-array.py
1 parent 78ebc07 commit f9a8a72

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
class Solution(object):
5+
def kthDistinct(self, arr, k):
6+
"""
7+
:type arr: List[str]
8+
:type k: int
9+
:rtype: str
10+
"""
11+
count = collections.Counter(arr)
12+
arr = [x for x in arr if count[x] == 1]
13+
return arr[k-1] if k-1 < len(arr) else ""

0 commit comments

Comments
 (0)