# 1079. Letter Tile Possibilities

You have `n`  `tiles`, where each tile has one letter `tiles[i]` printed on it.

Return  the number of possible non-empty sequences of letters  you can make using the letters printed on those `tiles`.

Example 1:

``````Input: tiles = "AAB"
Output: 8
Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".
``````

Example 2:

``````Input: tiles = "AAABBC"
Output: 188
``````

Example 3:

``````Input: tiles = "V"
Output: 1
``````

Constraints:

• `1 <= tiles.length <= 7`
• `tiles` consists of uppercase English letters.

``````class Solution {
public:
int numTilePossibilities(string tiles) {
vector<int> cnt(26);
for (char c : tiles) ++cnt[c - 'A'];
return helper(cnt);
}
int helper(vector<int>& cnt) {
int res = 0;
for (int i = 0; i < 26; ++i) {
if (cnt[i] == 0) continue;
++res;
--cnt[i];
res += helper(cnt);
++cnt[i];
}
return res;
}
};
``````

Github 同步地址:

https://github.com/grandyang/leetcode/issues/1079

https://leetcode.com/problems/letter-tile-possibilities/

https://leetcode.com/problems/letter-tile-possibilities/discuss/308284/Concise-java-solution

https://leetcode.com/problems/letter-tile-possibilities/discuss/308398/C%2B%2B-Permutation-of-Combinations

LeetCode All in One 题目讲解汇总(持续更新中…)

 微信打赏 Venmo 打赏
（欢迎加入博主的知识星球，博主将及时答疑解惑，并分享刷题经验与总结，试运营期间前五十位可享受半价优惠～）

×

Help us with donation