File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string[] } stickers
3
+ * @param {string } target
4
+ * @return {number }
5
+ */
6
+ const minStickers = function ( stickers , target ) {
7
+ const n = stickers . length
8
+ const m = target . length
9
+ const limit = 1 << m
10
+ const dp = Array ( limit ) . fill ( Infinity )
11
+ dp [ 0 ] = 0
12
+ for ( let i = 0 ; i < limit ; i ++ ) {
13
+ if ( dp [ i ] === Infinity ) continue
14
+ for ( const sticker of stickers ) {
15
+ let stat = i
16
+ for ( const ch of sticker ) {
17
+ for ( let j = 0 ; j < m ; j ++ ) {
18
+ if ( target [ j ] === ch && ( ( stat >> j ) & 1 ) === 0 ) {
19
+ stat |= ( 1 << j )
20
+ break
21
+ }
22
+ }
23
+ }
24
+ dp [ stat ] = Math . min ( dp [ stat ] , dp [ i ] + 1 )
25
+ }
26
+ }
27
+
28
+ return dp [ limit - 1 ] === Infinity ? - 1 : dp [ limit - 1 ]
29
+ }
30
+
31
+
32
+ // another
33
+
34
+
1
35
/**
2
36
* @param {string[] } stickers
3
37
* @param {string } target
You can’t perform that action at this time.
0 commit comments