HTMLify

LeetCode - Kth Distinct String in an Array - Python
Views: 22 | Author: abh
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]

Comments