Skip to content

Commit 91997a7

Browse files
authored
feat: add cs solution to lc problem: No. 935
1 parent 9ea4b3c commit 91997a7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)