Class Solution

java.lang.Object
g2701_2800.s2741_special_permutations.Solution

public class Solution extends Object
2741 - Special Permutations.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> containing <code>n</code> <strong>distinct</strong> positive integers. A permutation of <code>nums</code> is called special if:</p> <ul> <li>For all indexes <code>0 <= i < n - 1</code>, either <code>nums[i] % nums[i+1] == 0</code> or <code>nums[i+1] % nums[i] == 0</code>.</li> </ul> <p>Return _the total number of special permutations. _As the answer could be large, return it **modulo **<code>10<sup>9 </sup>+ 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [2,3,6]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> [3,6,2] and [2,6,3] are the two special permutations of nums.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,4,3]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> [3,1,4] and [4,1,3] are the two special permutations of nums.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= nums.length <= 14</code></li> <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • specialPerm

      public int specialPerm(int[] nums)