We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a41560b commit 9333a22Copy full SHA for 9333a22
823-binary-trees-with-factors.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * @param {number[]} A
3
+ * @return {number}
4
+ */
5
+const numFactoredBinaryTrees = function(A) {
6
+ const mod = 10 ** 9 + 7
7
+ let res = 0
8
+ A.sort((a, b) => a - b)
9
+ const dp = {}
10
+ for(let i = 0; i < A.length; i++) {
11
+ dp[A[i]] = 1
12
+ for(let j = 0; j < i; j++) {
13
+ if(A[i] % A[j] === 0 && dp.hasOwnProperty(Math.floor( A[i] / A[j]))) {
14
+ dp[A[i]] = (dp[A[i]] + dp[A[j]] * dp[Math.floor(A[i] / A[j])]) % mod
15
+ }
16
17
18
+ for(let el of Object.values(dp)) res = (res + el) % mod
19
+ return res
20
+};
0 commit comments