Skip to content
Open
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
47 changes: 47 additions & 0 deletions articles/height-checker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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<int> expected = new List<int>();
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)
Expand Down
10 changes: 5 additions & 5 deletions articles/pascals-triangle-ii.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Solution {

```csharp
public class Solution {
public IList<int> GetRow(int rowIndex) {
public List<int> GetRow(int rowIndex) {
if (rowIndex == 0) return new List<int> { 1 };

var curRow = new List<int> { 1 };
Expand Down Expand Up @@ -284,7 +284,7 @@ class Solution {

```csharp
public class Solution {
public IList<int> GetRow(int rowIndex) {
public List<int> GetRow(int rowIndex) {
var res = new List<int[]>();
for (int i = 0; i <= rowIndex; i++) {
int[] row = new int[i + 1];
Expand Down Expand Up @@ -462,7 +462,7 @@ class Solution {

```csharp
public class Solution {
public IList<int> GetRow(int rowIndex) {
public List<int> GetRow(int rowIndex) {
var res = new List<int> { 1 };
for (int i = 0; i < rowIndex; i++) {
var nextRow = new List<int>(new int[res.Count + 1]);
Expand Down Expand Up @@ -627,7 +627,7 @@ class Solution {

```csharp
public class Solution {
public IList<int> GetRow(int rowIndex) {
public List<int> GetRow(int rowIndex) {
var row = new List<int>(new int[rowIndex + 1]);
for (int i = 0; i <= rowIndex; i++) row[i] = 1;
for (int i = 1; i < rowIndex; i++) {
Expand Down Expand Up @@ -778,7 +778,7 @@ class Solution {

```csharp
public class Solution {
public IList<int> GetRow(int rowIndex) {
public List<int> GetRow(int rowIndex) {
var row = new List<int> { 1 };
for (int i = 1; i <= rowIndex; i++) {
row.Add((int)((long)row[row.Count - 1] * (rowIndex - i + 1) / i));
Expand Down
2 changes: 1 addition & 1 deletion articles/products-of-array-discluding-self.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down