File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 1818 n is in the range of [1, 106].
1919 */
2020public 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}
You can’t perform that action at this time.
0 commit comments