[LeetCode] Letter Tile Possibilities

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
int helper(vector<int>& chars) {
int res = 0;
for(int i = 0; i < 26; i++) {
if(chars[i]) {
chars[i]--;
res = res + helper(chars) + 1;
chars[i]++;
}
}
return res;
}
public:
int numTilePossibilities(string tiles) {
vector<int> chars(26,0);
for(auto ch : tiles) chars[ch-'A']++;
return helper(chars);
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/03/03/PS/LeetCode/letter-tile-possibilities/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.