diff --git a/articles/height-checker.md b/articles/height-checker.md index 89954f3c6..8d36a18bc 100644 --- a/articles/height-checker.md +++ b/articles/height-checker.md @@ -96,6 +96,25 @@ class Solution { } ``` +```csharp +public class Solution { + public int HeightChecker(int[] heights) { + int[] expected = new int[heights.Length]; + Array.Copy(heights, expected, heights.Length); + Array.Sort(expected); + + int res = 0; + for (int i = 0; i < heights.Length; i++) { + if (heights[i] != expected[i]) { + res++; + } + } + + return res; + } +} +``` + ```go func heightChecker(heights []int) int { expected := make([]int, len(heights)) @@ -303,6 +322,34 @@ class Solution { } ``` +```csharp +public class Solution { + public int HeightChecker(int[] heights) { + int[] count = new int[101]; + foreach (int h in heights) { + count[h]++; + } + + List expected = new List(); + for (int h = 1; h <= 100; h++) { + int c = count[h]; + for (int i = 0; i < c; i++) { + expected.Add(h); + } + } + + int res = 0; + for (int i = 0; i < heights.Length; i++) { + if (heights[i] != expected[i]) { + res++; + } + } + + return res; + } +} +``` + ```go func heightChecker(heights []int) int { count := make([]int, 101) diff --git a/articles/pascals-triangle-ii.md b/articles/pascals-triangle-ii.md index 4a5f2f6e1..40a81615f 100644 --- a/articles/pascals-triangle-ii.md +++ b/articles/pascals-triangle-ii.md @@ -103,7 +103,7 @@ class Solution { ```csharp public class Solution { - public IList GetRow(int rowIndex) { + public List GetRow(int rowIndex) { if (rowIndex == 0) return new List { 1 }; var curRow = new List { 1 }; @@ -284,7 +284,7 @@ class Solution { ```csharp public class Solution { - public IList GetRow(int rowIndex) { + public List GetRow(int rowIndex) { var res = new List(); for (int i = 0; i <= rowIndex; i++) { int[] row = new int[i + 1]; @@ -462,7 +462,7 @@ class Solution { ```csharp public class Solution { - public IList GetRow(int rowIndex) { + public List GetRow(int rowIndex) { var res = new List { 1 }; for (int i = 0; i < rowIndex; i++) { var nextRow = new List(new int[res.Count + 1]); @@ -627,7 +627,7 @@ class Solution { ```csharp public class Solution { - public IList GetRow(int rowIndex) { + public List GetRow(int rowIndex) { var row = new List(new int[rowIndex + 1]); for (int i = 0; i <= rowIndex; i++) row[i] = 1; for (int i = 1; i < rowIndex; i++) { @@ -778,7 +778,7 @@ class Solution { ```csharp public class Solution { - public IList GetRow(int rowIndex) { + public List GetRow(int rowIndex) { var row = new List { 1 }; for (int i = 1; i <= rowIndex; i++) { row.Add((int)((long)row[row.Count - 1] * (rowIndex - i + 1) / i)); diff --git a/articles/products-of-array-discluding-self.md b/articles/products-of-array-discluding-self.md index 1fd0bc614..e196fb7be 100644 --- a/articles/products-of-array-discluding-self.md +++ b/articles/products-of-array-discluding-self.md @@ -248,7 +248,7 @@ So we first check how many zeros the array has: - The index with zero gets the `prod` of all non-zero numbers. - All other positions get `0`. - If there are no zeros: - - Set each result value to `prod / nums[i]`. + - Set each result value to `prod // nums[i]`. 5. Return the result array. ::tabs-start