Class Solution
-
- All Implemented Interfaces:
public final class Solution2741 - Special Permutations.
Medium
You are given a 0-indexed integer array
numscontainingndistinct positive integers. A permutation ofnumsis called special if:For all indexes
0 <= i < n - 1, eithernums[i] % nums[i+1] == 0ornums[i+1] % nums[i] == 0.
Return _the total number of special permutations. _As the answer could be large, return it **modulo **<code>10<sup>9 </sup>+ 7</code>.
Example 1:
Input: nums = 2,3,6
Output: 2
Explanation: 3,6,2 and 2,6,3 are the two special permutations of nums.
Example 2:
Input: nums = 1,4,3
Output: 2
Explanation: 3,1,4 and 4,1,3 are the two special permutations of nums.
Constraints:
2 <= nums.length <= 14<code>1 <= numsi<= 10<sup>9</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerspecialPerm(IntArray nums)-
-
Method Detail
-
specialPerm
final Integer specialPerm(IntArray nums)
-
-
-
-