We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5735ba0 commit 57a924dCopy full SHA for 57a924d
C++/letter-tile-possibilities.cpp
@@ -46,3 +46,30 @@ class Solution {
46
return result;
47
}
48
};
49
+
50
+// Time: O(r), r is the value of result
51
+// Space: O(n)
52
+class Solution2 {
53
+public:
54
+ int numTilePossibilities(string tiles) {
55
+ unordered_map<char,int> count;
56
+ for (const auto& c : tiles) {
57
+ ++count[c];
58
+ }
59
+ return dfs(&count);
60
61
62
+private:
63
+ int dfs(unordered_map<char,int> *count) {
64
+ int total = 0;
65
+ for (auto& c : *count) {
66
+ if (c.second) {
67
+ --c.second;
68
+ total += 1 + dfs(count);
69
+ ++c.second;
70
71
72
+ return total;
73
74
+};
75
0 commit comments