Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit777a5cd

Browse files
refactor 634
1 parent5b05d77 commit777a5cd

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
publicclass_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-
privatestaticfinalintM =1000000007;
21+
publicstaticclassSolution1 {
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+
privatestaticfinalintM =1000000007;
2627

27-
publicintfindDerangement(intn) {
28-
longans =1;
29-
for (inti =1;i <=n;i++) {
30-
ans = (i *ans %M + (i %2 ==0 ?1 : -1)) %M;
28+
publicintfindDerangement(intn) {
29+
longans =1;
30+
for (inti =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)

[8]ページ先頭

©2009-2025 Movatter.jp