[LeetCode] Find the Derangement of An Array 找数组的错排

Posted Grandyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] Find the Derangement of An Array 找数组的错排相关的知识,希望对你有一定的参考价值。

 

In combinatorial mathematics, a derangement is a permutation of the elements of a set, such that no element appears in its original position.

There‘s originally an array consisting of n integers from 1 to n in ascending order, you need to find the number of derangement it can generate.

Also, since the answer may be very large, you should return the output mod 109 + 7.

Example 1:

Input: 3
Output: 2
Explanation: The original array is [1,2,3]. The two derangements are [2,3,1] and [3,1,2].

 

Note:
n is in the range of [1, 106].

 

s

 

以上是关于[LeetCode] Find the Derangement of An Array 找数组的错排的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode: Find the Duplicate Number

LeetCode 997. Find the Town Judge

Leetcode: Find the Difference

LeetCode 389. Find the Difference

Leetcode 389 Find the difference

LeetCode 389. Find the Difference