1160. Letter Tile Possibilities
My accepted Python solution to LeetCode problem 1160, Letter Tile Possibilities, running in 37ms.
- Difficulty: Medium
- Python
- Runtime 37ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 37ms, memory 17.5MB, accepted 2026-01-02.
class Solution:
def numTilePossibilities(self, tiles: str) -> int:
from collections import Counter
count = Counter(tiles)
def backtrack():
total = 0
for c in count:
if count[c] > 0:
# Use this character
total += 1
count[c] -= 1
# Continue building sequences
total += backtrack()
# Backtrack
count[c] += 1
return total
return backtrack()