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 2dc04df commit ad4b749Copy full SHA for ad4b749
solution/0900-0999/0935.Knight Dialer/README.md
@@ -195,6 +195,35 @@ func knightDialer(n int) int {
195
}
196
```
197
198
+### **C#**
199
+
200
+```cs
201
+public class Solution {
202
+ public int KnightDialer(int n) {
203
+ if (n == 1) return 10;
204
+ int A = 4;
205
+ int B = 2;
206
+ int C = 2;
207
+ int D = 1;
208
+ int MOD = (int)1e9 + 7;
209
+ for (int i = 0; i < n - 1; i++) {
210
+ int tempA = A;
211
+ int tempB = B;
212
+ int tempC = C;
213
+ int tempD = D;
214
+ A = ((2 * tempB) % MOD + (2 * tempC) % MOD) % MOD;
215
+ B = tempA;
216
+ C = (tempA + (2 * tempD) % MOD) % MOD;
217
+ D = tempC;
218
+ }
219
220
+ int ans = (A + B) % MOD;
221
+ ans = (ans + C) % MOD;
222
+ return (ans + D) % MOD;
223
224
+}
225
+```
226
227
### **...**
228
229
0 commit comments