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

Commit ed9518c

Browse files
feat: add cs solution to lc problem: No.0935 (doocs#2023)
1 parent 9ea4b3c commit ed9518c

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

‎solution/0900-0999/0935.Knight Dialer/README.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,35 @@ func knightDialer(n int) int {
195195
}
196196
```
197197

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+
198227
### **...**
199228

200229
```

‎solution/0900-0999/0935.Knight Dialer/README_EN.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,35 @@ func knightDialer(n int) int {
176176
}
177177
```
178178

179+
### **C#**
180+
181+
```cs
182+
public class Solution {
183+
public int KnightDialer(int n) {
184+
if (n == 1) return 10;
185+
int A = 4;
186+
int B = 2;
187+
int C = 2;
188+
int D = 1;
189+
int MOD = (int)1e9 + 7;
190+
for (int i = 0; i < n - 1; i++) {
191+
int tempA = A;
192+
int tempB = B;
193+
int tempC = C;
194+
int tempD = D;
195+
A = ((2 * tempB) % MOD + (2 * tempC) % MOD) % MOD;
196+
B = tempA;
197+
C = (tempA + (2 * tempD) % MOD) % MOD;
198+
D = tempC;
199+
}
200+
201+
int ans = (A + B) % MOD;
202+
ans = (ans + C) % MOD;
203+
return (ans + D) % MOD;
204+
}
205+
}
206+
```
207+
179208
### **...**
180209

181210
```
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)

AltStyle によって変換されたページ (->オリジナル) /