Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cs solution to lc problem: No. 935 #2023

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions solution/0900-0999/0935.Knight Dialer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,35 @@ func knightDialer(n int) int {
}
```

### **C#**

```cs
public class Solution {
public int KnightDialer(int n) {
if (n == 1) return 10;
int A = 4;
int B = 2;
int C = 2;
int D = 1;
int MOD = (int)1e9 + 7;
for (int i = 0; i < n - 1; i++) {
int tempA = A;
int tempB = B;
int tempC = C;
int tempD = D;
A = ((2 * tempB) % MOD + (2 * tempC) % MOD) % MOD;
B = tempA;
C = (tempA + (2 * tempD) % MOD) % MOD;
D = tempC;
}

int ans = (A + B) % MOD;
ans = (ans + C) % MOD;
return (ans + D) % MOD;
}
}
```

### **...**

```
Expand Down
29 changes: 29 additions & 0 deletions solution/0900-0999/0935.Knight Dialer/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,35 @@ func knightDialer(n int) int {
}
```

### **C#**

```cs
public class Solution {
public int KnightDialer(int n) {
if (n == 1) return 10;
int A = 4;
int B = 2;
int C = 2;
int D = 1;
int MOD = (int)1e9 + 7;
for (int i = 0; i < n - 1; i++) {
int tempA = A;
int tempB = B;
int tempC = C;
int tempD = D;
A = ((2 * tempB) % MOD + (2 * tempC) % MOD) % MOD;
B = tempA;
C = (tempA + (2 * tempD) % MOD) % MOD;
D = tempC;
}

int ans = (A + B) % MOD;
ans = (ans + C) % MOD;
return (ans + D) % MOD;
}
}
```

### **...**

```
Expand Down
24 changes: 24 additions & 0 deletions solution/0900-0999/0935.Knight Dialer/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class Solution {
public int KnightDialer(int n) {
if (n == 1) return 10;
int A = 4;
int B = 2;
int C = 2;
int D = 1;
int MOD = (int)1e9 + 7;
for (int i = 0; i < n - 1; i++) {
int tempA = A;
int tempB = B;
int tempC = C;
int tempD = D;
A = ((2 * tempB) % MOD + (2 * tempC) % MOD) % MOD;
B = tempA;
C = (tempA + (2 * tempD) % MOD) % MOD;
D = tempC;
}

int ans = (A + B) % MOD;
ans = (ans + C) % MOD;
return (ans + D) % MOD;
}
}