Skip to content

Commit 777a5cd

Browse files
refactor 634
1 parent 5b05d77 commit 777a5cd

File tree

1 file changed

+12
-10
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+12
-10
lines changed

src/main/java/com/fishercoder/solutions/_634.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
n is in the range of [1, 106].
1919
*/
2020
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;
2627

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;
3134
}
32-
return (int) ans;
3335
}
3436
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy