Skip to content

Commit 36cd5b9

Browse files
committed
Add solution #1079
1 parent bcf468c commit 36cd5b9

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@
402402
1047|[Remove All Adjacent Duplicates In String](./1047-remove-all-adjacent-duplicates-in-string.js)|Easy|
403403
1051|[Height Checker](./1051-height-checker.js)|Easy|
404404
1071|[Greatest Common Divisor of Strings](./1071-greatest-common-divisor-of-strings.js)|Easy|
405+
1079|[Letter Tile Possibilities](./1079-letter-tile-possibilities.js)|Medium|
405406
1081|[Smallest Subsequence of Distinct Characters](./1081-smallest-subsequence-of-distinct-characters.js)|Medium|
406407
1103|[Distribute Candies to People](./1103-distribute-candies-to-people.js)|Easy|
407408
1108|[Defanging an IP Address](./1108-defanging-an-ip-address.js)|Easy|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 1079. Letter Tile Possibilities
3+
* https://leetcode.com/problems/letter-tile-possibilities/
4+
* Difficulty: Medium
5+
*
6+
* You have n tiles, where each tile has one letter tiles[i] printed on it.
7+
*
8+
* Return the number of possible non-empty sequences of letters you can make using the letters
9+
* printed on those tiles.
10+
*/
11+
12+
/**
13+
* @param {string} tiles
14+
* @return {number}
15+
*/
16+
var numTilePossibilities = function(tiles) {
17+
const map = {};
18+
tiles.split('').forEach(t => map[t] = (map[t] ?? 0) + 1);
19+
return backtrack();
20+
21+
function backtrack() {
22+
let count = 0;
23+
for (const key of Object.keys(map)) {
24+
if (!map[key]) continue;
25+
count += 1;
26+
map[key] -= 1;
27+
count += backtrack();
28+
map[key] += 1;
29+
}
30+
return count;
31+
}
32+
};

0 commit comments

Comments
 (0)