码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-07-20 15:11:18      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:ons   math   should   app   int   nal   nbsp   rate   als   

 

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 找数组的错排

标签:ons   math   should   app   int   nal   nbsp   rate   als   

原文地址:http://www.cnblogs.com/grandyang/p/7210929.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!