-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1079.cpp
More file actions
29 lines (28 loc) · 844 Bytes
/
1079.cpp
File metadata and controls
29 lines (28 loc) · 844 Bytes
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
class Solution {
public:
unordered_set<string> st;
void backtracking(string& tiles, int mask, string& current, int index) {
if (current.size() >= 1) st.insert(current);
if (index == tiles.size()) {
return;
}
else {
int n = tiles.size();
for (int i = 0; i < n; ++i) {
if (!(mask & (1 << i))) {
current.push_back(tiles[i]);
mask ^= (1 << i);
backtracking(tiles, mask, current, index + 1);
mask ^= (1 << i);
current.pop_back();
}
}
}
}
int numTilePossibilities(string tiles) {
string current = "";
int mask = 0;
backtracking(tiles, mask, current, 0);
return st.size();
}
};