We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9ea4b3c commit 91997a7Copy full SHA for 91997a7
solution/0900-0999/0935.Knight Dialer/Solution.cs
@@ -0,0 +1,24 @@
1
+public class Solution {
2
+ public int KnightDialer(int n) {
3
+ if (n == 1) return 10;
4
+ int A = 4;
5
+ int B = 2;
6
+ int C = 2;
7
+ int D = 1;
8
+ int MOD = (int)1e9 + 7;
9
+ for (int i = 0; i < n - 1; i++) {
10
+ int tempA = A;
11
+ int tempB = B;
12
+ int tempC = C;
13
+ int tempD = D;
14
+ A = ((2 * tempB) % MOD + (2 * tempC) % MOD) % MOD;
15
+ B = tempA;
16
+ C = (tempA + (2 * tempD) % MOD) % MOD;
17
+ D = tempC;
18
+ }
19
+
20
+ int ans = (A + B) % MOD;
21
+ ans = (ans + C) % MOD;
22
+ return (ans + D) % MOD;
23
24
+}
0 commit comments