File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 582
582
622|[ Design Circular Queue] ( ./solutions/0622-design-circular-queue.js ) |Medium|
583
583
623|[ Add One Row to Tree] ( ./solutions/0623-add-one-row-to-tree.js ) |Medium|
584
584
624|[ Maximum Distance in Arrays] ( ./solutions/0624-maximum-distance-in-arrays.js ) |Medium|
585
+ 625|[ Minimum Factorization] ( ./solutions/0625-minimum-factorization.js ) |Medium|
585
586
628|[ Maximum Product of Three Numbers] ( ./solutions/0628-maximum-product-of-three-numbers.js ) |Easy|
586
587
629|[ K Inverse Pairs Array] ( ./solutions/0629-k-inverse-pairs-array.js ) |Hard|
587
588
630|[ Course Schedule III] ( ./solutions/0630-course-schedule-iii.js ) |Hard|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 625. Minimum Factorization
3
+ * https://leetcode.com/problems/minimum-factorization/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given a positive integer num, return the smallest positive integer x whose multiplication
7
+ * of each digit equals num. If there is no answer or the answer is not fit in 32-bit signed
8
+ * integer, return 0.
9
+ */
10
+
11
+ /**
12
+ * @param {number } num
13
+ * @return {number }
14
+ */
15
+ var smallestFactorization = function ( num ) {
16
+ if ( num < 2 ) return num ;
17
+
18
+ const digits = [ ] ;
19
+ for ( let divisor = 9 ; divisor > 1 ; divisor -- ) {
20
+ while ( num % divisor === 0 ) {
21
+ digits . push ( divisor ) ;
22
+ num /= divisor ;
23
+ }
24
+ }
25
+
26
+ if ( num > 1 ) return 0 ;
27
+
28
+ let result = 0 ;
29
+ for ( const digit of digits . reverse ( ) ) {
30
+ result = result * 10 + digit ;
31
+ if ( result > 2 ** 31 - 1 ) return 0 ;
32
+ }
33
+
34
+ return result ;
35
+ } ;
You can’t perform that action at this time.
0 commit comments