forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0823.cpp
More file actions
29 lines (21 loc) · 830 Bytes
/
0823.cpp
File metadata and controls
29 lines (21 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public:
int numFactoredBinaryTrees(vector<int>& arr) {
unordered_map<int,long long int>map;
sort(arr.begin(),arr.end());
for(int i = 0; i < size(arr); i++)
map.insert({arr[i],1});
for(int i = 1; i < size(arr); i++){
long long int count = 0;
for(int j = 0; j < i; j++)
if(arr[i] % arr[j] == 0)
if(map.find(arr[i] / arr[j]) != map.end())
count += map.find(arr[j]) -> second * map.find(arr[i] / arr[j]) -> second;
map.find(arr[i]) -> second += count;
}
long long int sum = 0;
for(auto& it : map)
sum += it.second;
return sum % 1000000007;
}
};