Skip to content

Commit a593b75

Browse files
authored
feat: add C# solution to lc problem: No.0621 (doocs#861)
No.0621.Task Scheduler
1 parent 3cc2400 commit a593b75

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/0600-0699/0621.Task Scheduler/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ func max(a, b int) int {
158158
}
159159
```
160160

161+
### **C#**
162+
163+
```cs
164+
public class Solution {
165+
public int LeastInterval(char[] tasks, int n) {
166+
int[] cnt = new int[26];
167+
int x = 0;
168+
foreach (char c in tasks) {
169+
cnt[c - 'A']++;
170+
x = Math.Max(x, cnt[c - 'A']);
171+
}
172+
int s = 0;
173+
foreach (int v in cnt) {
174+
s = v == x ? s + 1 : s;
175+
}
176+
return Math.Max(tasks.Length, (x - 1) * (n + 1) + s);
177+
}
178+
}
179+
```
180+
161181
### **...**
162182

163183
```

solution/0600-0699/0621.Task Scheduler/README_EN.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ func max(a, b int) int {
141141
}
142142
```
143143

144+
### **C#**
145+
146+
```cs
147+
public class Solution {
148+
public int LeastInterval(char[] tasks, int n) {
149+
int[] cnt = new int[26];
150+
int x = 0;
151+
foreach (char c in tasks) {
152+
cnt[c - 'A']++;
153+
x = Math.Max(x, cnt[c - 'A']);
154+
}
155+
int s = 0;
156+
foreach (int v in cnt) {
157+
s = v == x ? s + 1 : s;
158+
}
159+
return Math.Max(tasks.Length, (x - 1) * (n + 1) + s);
160+
}
161+
}
162+
```
163+
144164
### **...**
145165

146166
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class Solution {
2+
public int LeastInterval(char[] tasks, int n) {
3+
int[] cnt = new int[26];
4+
int x = 0;
5+
foreach (char c in tasks) {
6+
cnt[c - 'A']++;
7+
x = Math.Max(x, cnt[c - 'A']);
8+
}
9+
int s = 0;
10+
foreach (int v in cnt) {
11+
s = v == x ? s + 1 : s;
12+
}
13+
return Math.Max(tasks.Length, (x - 1) * (n + 1) + s);
14+
}
15+
}

0 commit comments

Comments
 (0)