From cd8c994abcc72225b1948a538be6b3bbb3547fa6 Mon Sep 17 00:00:00 2001 From: Yihua Wang Date: Fri, 7 Oct 2022 15:21:02 +0800 Subject: [PATCH 1/2] add C# solution to lc problem: No.621 --- .../0600-0699/0621.Task Scheduler/README.md | 20 ++++++++++++++++--- .../0621.Task Scheduler/README_EN.md | 20 ++++++++++++++++--- .../0600-0699/0621.Task Scheduler/Solution.cs | 15 ++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 solution/0600-0699/0621.Task Scheduler/Solution.cs diff --git a/solution/0600-0699/0621.Task Scheduler/README.md b/solution/0600-0699/0621.Task Scheduler/README.md index c0f89402f1826..6421d0d8ab9a6 100644 --- a/solution/0600-0699/0621.Task Scheduler/README.md +++ b/solution/0600-0699/0621.Task Scheduler/README.md @@ -158,10 +158,24 @@ func max(a, b int) int { } ``` -### **...** - -``` +### **C#** +```C# +public class Solution { + public int LeastInterval(char[] tasks, int n) { + int[] cnt = new int[26]; + int x = 0; + foreach (char c in tasks) { + cnt[c - 'A']++; + x = Math.Max(x, cnt[c - 'A']); + } + int s = 0; + foreach (int v in cnt) { + s = v == x ? s + 1 : s; + } + return Math.Max(tasks.Length, (x - 1) * (n + 1) + s); + } +} ``` diff --git a/solution/0600-0699/0621.Task Scheduler/README_EN.md b/solution/0600-0699/0621.Task Scheduler/README_EN.md index 8c52ed4a66c6f..76980e8d08e77 100644 --- a/solution/0600-0699/0621.Task Scheduler/README_EN.md +++ b/solution/0600-0699/0621.Task Scheduler/README_EN.md @@ -141,10 +141,24 @@ func max(a, b int) int { } ``` -### **...** - -``` +### **C#** +```C# +public class Solution { + public int LeastInterval(char[] tasks, int n) { + int[] cnt = new int[26]; + int x = 0; + foreach (char c in tasks) { + cnt[c - 'A']++; + x = Math.Max(x, cnt[c - 'A']); + } + int s = 0; + foreach (int v in cnt) { + s = v == x ? s + 1 : s; + } + return Math.Max(tasks.Length, (x - 1) * (n + 1) + s); + } +} ``` diff --git a/solution/0600-0699/0621.Task Scheduler/Solution.cs b/solution/0600-0699/0621.Task Scheduler/Solution.cs new file mode 100644 index 0000000000000..efeae187abc15 --- /dev/null +++ b/solution/0600-0699/0621.Task Scheduler/Solution.cs @@ -0,0 +1,15 @@ +public class Solution { + public int LeastInterval(char[] tasks, int n) { + int[] cnt = new int[26]; + int x = 0; + foreach (char c in tasks) { + cnt[c - 'A']++; + x = Math.Max(x, cnt[c - 'A']); + } + int s = 0; + foreach (int v in cnt) { + s = v == x ? s + 1 : s; + } + return Math.Max(tasks.Length, (x - 1) * (n + 1) + s); + } +} \ No newline at end of file From 6b783ca0d50127565303b60588a1d657ca770bcc Mon Sep 17 00:00:00 2001 From: Yihua Wang Date: Fri, 7 Oct 2022 15:54:59 +0800 Subject: [PATCH 2/2] Update --- solution/0600-0699/0621.Task Scheduler/README.md | 8 +++++++- solution/0600-0699/0621.Task Scheduler/README_EN.md | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/solution/0600-0699/0621.Task Scheduler/README.md b/solution/0600-0699/0621.Task Scheduler/README.md index 6421d0d8ab9a6..a38007b786a2d 100644 --- a/solution/0600-0699/0621.Task Scheduler/README.md +++ b/solution/0600-0699/0621.Task Scheduler/README.md @@ -160,7 +160,7 @@ func max(a, b int) int { ### **C#** -```C# +```cs public class Solution { public int LeastInterval(char[] tasks, int n) { int[] cnt = new int[26]; @@ -178,4 +178,10 @@ public class Solution { } ``` +### **...** + +``` + +``` + diff --git a/solution/0600-0699/0621.Task Scheduler/README_EN.md b/solution/0600-0699/0621.Task Scheduler/README_EN.md index 76980e8d08e77..992fba8a91950 100644 --- a/solution/0600-0699/0621.Task Scheduler/README_EN.md +++ b/solution/0600-0699/0621.Task Scheduler/README_EN.md @@ -143,7 +143,7 @@ func max(a, b int) int { ### **C#** -```C# +```cs public class Solution { public int LeastInterval(char[] tasks, int n) { int[] cnt = new int[26]; @@ -161,4 +161,10 @@ public class Solution { } ``` +### **...** + +``` + +``` +