Skip to content

[pull] main from doocs:main #357

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

Merged
merged 3 commits into from
Feb 13, 2025
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
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ node_modules/
/solution/3100-3199/3150.Invalid Tweets II/Solution.sql
/solution/3100-3199/3198.Find Cities in Each State/Solution.sql
/solution/3300-3399/3328.Find Cities in Each State II/Solution.sql
/solution/3400-3499/3451.Find Invalid IP Addresses/Solution.sql
16 changes: 16 additions & 0 deletions solution/0000-0099/0027.Remove Element/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ var removeElement = function (nums, val) {
};
```

#### C#

```cs
public class Solution {
public int RemoveElement(int[] nums, int val) {
int k = 0;
foreach (int x in nums) {
if (x != val) {
nums[k++] = x;
}
}
return k;
}
}
```

#### PHP

```php
Expand Down
16 changes: 16 additions & 0 deletions solution/0000-0099/0027.Remove Element/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ var removeElement = function (nums, val) {
};
```

#### C#

```cs
public class Solution {
public int RemoveElement(int[] nums, int val) {
int k = 0;
foreach (int x in nums) {
if (x != val) {
nums[k++] = x;
}
}
return k;
}
}
```

#### PHP

```php
Expand Down
11 changes: 11 additions & 0 deletions solution/0000-0099/0027.Remove Element/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Solution {
public int RemoveElement(int[] nums, int val) {
int k = 0;
foreach (int x in nums) {
if (x != val) {
nums[k++] = x;
}
}
return k;
}
}
67 changes: 64 additions & 3 deletions solution/1700-1799/1742.Maximum Number of Balls in a Box/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ tags:

### 方法一:数组 + 模拟

观察题目的数据范围,小球的编号最大不超过 $10^5$,那么每个编号的各个位数之和的最大值小于 $50$。因此,我们可以直接开一个长度为 $50$ 的数组 $cnt$ 来统计每个编号的各个位数之和的数量。
观察题目的数据范围,小球的编号最大不超过 $10^5$,那么每个编号的各个位数之和的最大值小于 $50$。因此,我们可以直接开一个长度为 $50$ 的数组 $\textit{cnt}$ 来统计每个编号的各个位数之和的数量。

答案就是数组 $cnt$ 中的最大值。
答案就是数组 $\textit{cnt}$ 中的最大值。

时间复杂度 $O(n \times \log_{10}m)$。其中 $n = highLimit - lowLimit + 1$,而 $m = highLimit$。
时间复杂度 $O(n \times \log_{10}m)$。其中 $n = \textit{highLimit} - \textit{lowLimit} + 1$,而 $m = \textit{highLimit}$。

<!-- tabs:start -->

Expand Down Expand Up @@ -172,6 +172,67 @@ function countBalls(lowLimit: number, highLimit: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn count_balls(low_limit: i32, high_limit: i32) -> i32 {
let mut cnt = vec![0; 50];
for x in low_limit..=high_limit {
let mut y = 0;
let mut n = x;
while n > 0 {
y += n % 10;
n /= 10;
}
cnt[y as usize] += 1;
}
*cnt.iter().max().unwrap()
}
}
```

#### JavaScript

```js
/**
* @param {number} lowLimit
* @param {number} highLimit
* @return {number}
*/
var countBalls = function (lowLimit, highLimit) {
const cnt = Array(50).fill(0);
for (let i = lowLimit; i <= highLimit; ++i) {
let y = 0;
for (let x = i; x; x = Math.floor(x / 10)) {
y += x % 10;
}
++cnt[y];
}
return Math.max(...cnt);
};
```

#### C#

```cs
public class Solution {
public int CountBalls(int lowLimit, int highLimit) {
int[] cnt = new int[50];
for (int x = lowLimit; x <= highLimit; x++) {
int y = 0;
int n = x;
while (n > 0) {
y += n % 10;
n /= 10;
}
cnt[y]++;
}
return cnt.Max();
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ Box 10 has the most number of balls with 2 balls.

### Solution 1: Array + Simulation

Observing the data range of the problem, the maximum number of the ball does not exceed $10^5$, so the maximum value of the sum of each digit of the number is less than $50$. Therefore, we can directly create an array $cnt$ with a length of $50$ to count the number of each digit sum of each number.
Observing the problem's data range, the maximum number of balls does not exceed $10^5$, so the maximum sum of the digits of each number is less than $50$. Therefore, we can directly create an array $\textit{cnt}$ of length $50$ to count the number of occurrences of each digit sum.

The answer is the maximum value in the array $cnt$.
The answer is the maximum value in the array $\textit{cnt}$.

The time complexity is $O(n \times \log_{10}m)$. Here, $n = highLimit - lowLimit + 1$, and $m = highLimit$.
The time complexity is $O(n \times \log_{10}m)$. Here, $n = \textit{highLimit} - \textit{lowLimit} + 1$, and $m = \textit{highLimit}$.

<!-- tabs:start -->

Expand Down Expand Up @@ -170,6 +170,67 @@ function countBalls(lowLimit: number, highLimit: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn count_balls(low_limit: i32, high_limit: i32) -> i32 {
let mut cnt = vec![0; 50];
for x in low_limit..=high_limit {
let mut y = 0;
let mut n = x;
while n > 0 {
y += n % 10;
n /= 10;
}
cnt[y as usize] += 1;
}
*cnt.iter().max().unwrap()
}
}
```

#### JavaScript

```js
/**
* @param {number} lowLimit
* @param {number} highLimit
* @return {number}
*/
var countBalls = function (lowLimit, highLimit) {
const cnt = Array(50).fill(0);
for (let i = lowLimit; i <= highLimit; ++i) {
let y = 0;
for (let x = i; x; x = Math.floor(x / 10)) {
y += x % 10;
}
++cnt[y];
}
return Math.max(...cnt);
};
```

#### C#

```cs
public class Solution {
public int CountBalls(int lowLimit, int highLimit) {
int[] cnt = new int[50];
for (int x = lowLimit; x <= highLimit; x++) {
int y = 0;
int n = x;
while (n > 0) {
y += n % 10;
n /= 10;
}
cnt[y]++;
}
return cnt.Max();
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Solution {
public int CountBalls(int lowLimit, int highLimit) {
int[] cnt = new int[50];
for (int x = lowLimit; x <= highLimit; x++) {
int y = 0;
int n = x;
while (n > 0) {
y += n % 10;
n /= 10;
}
cnt[y]++;
}
return cnt.Max();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @param {number} lowLimit
* @param {number} highLimit
* @return {number}
*/
var countBalls = function (lowLimit, highLimit) {
const cnt = Array(50).fill(0);
for (let i = lowLimit; i <= highLimit; ++i) {
let y = 0;
for (let x = i; x; x = Math.floor(x / 10)) {
y += x % 10;
}
++cnt[y];
}
return Math.max(...cnt);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
impl Solution {
pub fn count_balls(low_limit: i32, high_limit: i32) -> i32 {
let mut cnt = vec![0; 50];
for x in low_limit..=high_limit {
let mut y = 0;
let mut n = x;
while n > 0 {
y += n % 10;
n /= 10;
}
cnt[y as usize] += 1;
}
*cnt.iter().max().unwrap()
}
}
Loading