首页 > 代码库 > [LeetCode] Find the Derangement of An Array 找数组的错排
[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: 3Output: 2Explanation: 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 找数组的错排
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。