Skip to content

Commit 85c784f

Browse files
authored
Create 1079. Letter Tile Possibilities (#718)
2 parents 9b5e882 + e9f240d commit 85c784f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

1079. Letter Tile Possibilities

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
void count(vector<int> &arr, int n, int &ans){
4+
//checks if every place is filled.
5+
if(n <= 0) return;
6+
//checking for letters which can be filled at nth index.
7+
for(int i = 0; i < 26; i++){
8+
if(arr[i] > 0){
9+
// Reducing its occurence.
10+
arr[i]--;
11+
ans++;
12+
count(arr, n - 1, ans);
13+
//Restoring its occurence for furthur combination./Backtracking.
14+
arr[i]++;
15+
}
16+
}
17+
}
18+
int numTilePossibilities(string tiles) {
19+
vector<int> arr(26, 0);
20+
//Occurence count array.
21+
for(int i = 0; i < tiles.size(); i++){
22+
arr[int(tiles[i]) - 65]++;
23+
}
24+
int ans = 0;
25+
count(arr, tiles.size(), ans);
26+
return ans;
27+
}
28+
};

0 commit comments

Comments
 (0)