Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - Kth Distinct String in an Array - Python
Views: 404 | Author: abh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class Solution:
    def kthDistinct(self, arr: List[str], k: int) -> str:
        distinct = []
        for c in arr:
            if arr.count(c) > 1:
                continue
            if c not in distinct:
                distinct.append(c)
        if len(distinct) < k:
            return ""
        return distinct[k-1]