aboutsummaryrefslogtreecommitdiff
path: root/letter_tile_possibilities.py
blob: 3d5e883e07a35c6849674bec591f5d51dfa799d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 1079. Letter Tile Possibilities

"""
given 'n' tiles where each tile has one letter ('tiles[i]') printed on it.
return the number of possible non-empty letters printed on those tiles.
"""


class Solution(object):
    def numTilePossibilities(self, tiles):
        """
        :type tiles: str
        :rtype: int
        """
        ans = set()

        def dfs(path, tiles):
            if path:
                ans.add(path)
            for i in range(len(tiles)):
                dfs(path + tiles[i], tiles[:i] + tiles[i + 1 :])

        dfs("", tiles)
        return len(ans)


if __name__ == "__main__":
    obj = Solution()
    print(obj.numTilePossibilities("AAB"))
    print(obj.numTilePossibilities("AAABBC"))
    print(obj.numTilePossibilities("V"))