File tree 1 file changed +12
-10
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 18
18
n is in the range of [1, 106].
19
19
*/
20
20
public class _634 {
21
- /**
22
- * reference: https://discuss.leetcode.com/topic/94442/java-5-lines-o-1-space-solution
23
- * and https://leetcode.com/articles/find-derangements/#approach-5-using-formula-accepted
24
- */
25
- private static final int M = 1000000007 ;
21
+ public static class Solution1 {
22
+ /**
23
+ * reference: https://discuss.leetcode.com/topic/94442/java-5-lines-o-1-space-solution
24
+ * and https://leetcode.com/articles/find-derangements/#approach-5-using-formula-accepted
25
+ */
26
+ private static final int M = 1000000007 ;
26
27
27
- public int findDerangement (int n ) {
28
- long ans = 1 ;
29
- for (int i = 1 ; i <= n ; i ++) {
30
- ans = (i * ans % M + (i % 2 == 0 ? 1 : -1 )) % M ;
28
+ public int findDerangement (int n ) {
29
+ long ans = 1 ;
30
+ for (int i = 1 ; i <= n ; i ++) {
31
+ ans = (i * ans % M + (i % 2 == 0 ? 1 : -1 )) % M ;
32
+ }
33
+ return (int ) ans ;
31
34
}
32
- return (int ) ans ;
33
35
}
34
36
}
You can’t perform that action at this time.
0 commit comments