File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 402
402
1047|[ Remove All Adjacent Duplicates In String] ( ./1047-remove-all-adjacent-duplicates-in-string.js ) |Easy|
403
403
1051|[ Height Checker] ( ./1051-height-checker.js ) |Easy|
404
404
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|
405
406
1081|[ Smallest Subsequence of Distinct Characters] ( ./1081-smallest-subsequence-of-distinct-characters.js ) |Medium|
406
407
1103|[ Distribute Candies to People] ( ./1103-distribute-candies-to-people.js ) |Easy|
407
408
1108|[ Defanging an IP Address] ( ./1108-defanging-an-ip-address.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments