823. Binary Trees With Factors Medium

@problem@discussion
#Array#Hash Table#Dynamic Programming



1/**
2 * [823] Binary Trees With Factors
3 *
4 * Given an array of unique integers, arr, where each integer arr[i] is strictly greater than 1.
5 * We make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node's value should be equal to the product of the values of its children.
6 * Return the number of binary trees we can make. The answer may be too large so return the answer modulo 10^9 + 7.
7 *  
8 * Example 1:
9 * 
10 * Input: arr = [2,4]
11 * Output: 3
12 * Explanation: We can make these trees: [2], [4], [4, 2, 2]
13 * Example 2:
14 * 
15 * Input: arr = [2,4,5,10]
16 * Output: 7
17 * Explanation: We can make these trees: [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2].
18 *  
19 * Constraints:
20 * 
21 * 	1 <= arr.length <= 1000
22 * 	2 <= arr[i] <= 10^9
23 * 	All the values of arr are unique.
24 * 
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/binary-trees-with-factors/
29// discuss: https://leetcode.com/problems/binary-trees-with-factors/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34    pub fn num_factored_binary_trees(arr: Vec<i32>) -> i32 {
35        0
36    }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_823() {
47    }
48}
49


Back
© 2025 bowen.ge All Rights Reserved.