Skip to content

feat: add solutions to lc problems: No.3201,3202 #4571

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 1 commit into from
Jul 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,47 @@ function maximumLength(nums: number[]): number {
}
```

#### Rust

```rust
impl Solution {
pub fn maximum_length(nums: Vec<i32>) -> i32 {
let mut f = [[0; 2]; 2];
let mut ans = 0;
for x in nums {
let x = (x % 2) as usize;
for j in 0..2 {
let y = ((j + 2 - x) % 2) as usize;
f[x][y] = f[y][x] + 1;
ans = ans.max(f[x][y]);
}
}
ans
}
}
```

#### C#

```cs
public class Solution {
public int MaximumLength(int[] nums) {
int k = 2;
int[,] f = new int[k, k];
int ans = 0;
foreach (int num in nums) {
int x = num % k;
for (int j = 0; j < k; ++j) {
int y = (j - x + k) % k;
f[x, y] = f[y, x] + 1;
ans = Math.Max(ans, f[x, y]);
}
}
return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,47 @@ function maximumLength(nums: number[]): number {
}
```

#### Rust

```rust
impl Solution {
pub fn maximum_length(nums: Vec<i32>) -> i32 {
let mut f = [[0; 2]; 2];
let mut ans = 0;
for x in nums {
let x = (x % 2) as usize;
for j in 0..2 {
let y = ((j + 2 - x) % 2) as usize;
f[x][y] = f[y][x] + 1;
ans = ans.max(f[x][y]);
}
}
ans
}
}
```

#### C#

```cs
public class Solution {
public int MaximumLength(int[] nums) {
int k = 2;
int[,] f = new int[k, k];
int ans = 0;
foreach (int num in nums) {
int x = num % k;
for (int j = 0; j < k; ++j) {
int y = (j - x + k) % k;
f[x, y] = f[y, x] + 1;
ans = Math.Max(ans, f[x, y]);
}
}
return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Solution {
public int MaximumLength(int[] nums) {
int k = 2;
int[,] f = new int[k, k];
int ans = 0;
foreach (int num in nums) {
int x = num % k;
for (int j = 0; j < k; ++j) {
int y = (j - x + k) % k;
f[x, y] = f[y, x] + 1;
ans = Math.Max(ans, f[x, y]);
}
}
return ans;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
impl Solution {
pub fn maximum_length(nums: Vec<i32>) -> i32 {
let mut f = [[0; 2]; 2];
let mut ans = 0;
for x in nums {
let x = (x % 2) as usize;
for j in 0..2 {
let y = ((j + 2 - x) % 2) as usize;
f[x][y] = f[y][x] + 1;
ans = ans.max(f[x][y]);
}
}
ans
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,47 @@ function maximumLength(nums: number[], k: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn maximum_length(nums: Vec<i32>, k: i32) -> i32 {
let k = k as usize;
let mut f = vec![vec![0; k]; k];
let mut ans = 0;
for x in nums {
let x = (x % k as i32) as usize;
for j in 0..k {
let y = (j + k - x) % k;
f[x][y] = f[y][x] + 1;
ans = ans.max(f[x][y]);
}
}
ans
}
}
```

#### C#

```cs
public class Solution {
public int MaximumLength(int[] nums, int k) {
int[,] f = new int[k, k];
int ans = 0;
foreach (int num in nums) {
int x = num % k;
for (int j = 0; j < k; ++j) {
int y = (j - x + k) % k;
f[x, y] = f[y, x] + 1;
ans = Math.Max(ans, f[x, y]);
}
}
return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,47 @@ function maximumLength(nums: number[], k: number): number {
}
```

#### Rust

```rust
impl Solution {
pub fn maximum_length(nums: Vec<i32>, k: i32) -> i32 {
let k = k as usize;
let mut f = vec![vec![0; k]; k];
let mut ans = 0;
for x in nums {
let x = (x % k as i32) as usize;
for j in 0..k {
let y = (j + k - x) % k;
f[x][y] = f[y][x] + 1;
ans = ans.max(f[x][y]);
}
}
ans
}
}
```

#### C#

```cs
public class Solution {
public int MaximumLength(int[] nums, int k) {
int[,] f = new int[k, k];
int ans = 0;
foreach (int num in nums) {
int x = num % k;
for (int j = 0; j < k; ++j) {
int y = (j - x + k) % k;
f[x, y] = f[y, x] + 1;
ans = Math.Max(ans, f[x, y]);
}
}
return ans;
}
}
```

<!-- 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 MaximumLength(int[] nums, int k) {
int[,] f = new int[k, k];
int ans = 0;
foreach (int num in nums) {
int x = num % k;
for (int j = 0; j < k; ++j) {
int y = (j - x + k) % k;
f[x, y] = f[y, x] + 1;
ans = Math.Max(ans, f[x, y]);
}
}
return ans;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
impl Solution {
pub fn maximum_length(nums: Vec<i32>, k: i32) -> i32 {
let k = k as usize;
let mut f = vec![vec![0; k]; k];
let mut ans = 0;
for x in nums {
let x = (x % k as i32) as usize;
for j in 0..k {
let y = (j + k - x) % k;
f[x][y] = f[y][x] + 1;
ans = ans.max(f[x][y]);
}
}
ans
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ tags:

<p>另外给你一个二维整数数组 <code>waitCost</code>,其中 <code>waitCost[i][j]</code> 定义了在该单元格&nbsp;<strong>等待&nbsp;</strong>的成本。</p>

<p>你从第 1 秒开始在单元格 <code>(0, 0)</code>。</p>
<p>路径始终从第 1 步进入单元格 <code>(0, 0)</code>&nbsp;并支付入场花费开始。</p>

<p>每一步,你都遵循交替模式:</p>

<ul>
<li>在&nbsp;<strong>奇数秒&nbsp;</strong>,你必须向&nbsp;<strong>右&nbsp;</strong>或向&nbsp;<strong>下&nbsp;</strong>移动到&nbsp;<strong>相邻&nbsp;</strong>的单元格,并支付其进入成本。</li>
<li>在&nbsp;<strong>偶数秒&nbsp;</strong>,你必须原地&nbsp;<strong>等待&nbsp;</strong>,并支付 <code>waitCost[i][j]</code>。</li>
<li>在&nbsp;<strong>偶数秒&nbsp;</strong>,你必须原地&nbsp;<strong>等待</strong><strong>恰好</strong>&nbsp;1 秒并在 1 秒期间支付 <code>waitCost[i][j]</code>。</li>
</ul>

<p>返回到达 <code>(m - 1, n - 1)</code> 所需的&nbsp;<strong>最小&nbsp;</strong>总成本。</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ tags:

<p>You are also given a 2D integer array <code>waitCost</code> where <code>waitCost[i][j]</code> defines the cost to <strong>wait</strong> on that cell.</p>

<p>You start at cell <code>(0, 0)</code> at second 1.</p>
<p>The path will always begin by entering cell <code>(0, 0)</code> on move 1 and paying the entrance cost.</p>

<p>At each step, you follow an alternating pattern:</p>

<ul>
<li>On <strong>odd-numbered</strong> seconds, you must move <strong>right</strong> or <strong>down</strong> to an <strong>adjacent</strong> cell, paying its entry cost.</li>
<li>On <strong>even-numbered</strong> seconds, you must <strong>wait</strong> in place, paying <code>waitCost[i][j]</code>.</li>
<li>On <strong>even-numbered</strong> seconds, you must <strong>wait</strong> in place for <strong>exactly</strong> one second and pay <code>waitCost[i][j]</code> during that second.</li>
</ul>

<p>Return the <strong>minimum</strong> total cost required to reach <code>(m - 1, n - 1)</code>.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3612.Process%20String%20with%20Special%20Operations%20I/README.md
tags:
- 字符串
- 模拟
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3612.Process%20String%20with%20Special%20Operations%20I/README_EN.md
tags:
- String
- Simulation
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3613.Minimize%20Maximum%20Component%20Cost/README.md
tags:
- 排序
- 并查集
- 图
- 二分查找
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3613.Minimize%20Maximum%20Component%20Cost/README_EN.md
tags:
- Sort
- Union Find
- Graph
- Binary Search
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3614.Process%20String%20with%20Special%20Operations%20II/README.md
tags:
- 字符串
- 模拟
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3614.Process%20String%20with%20Special%20Operations%20II/README_EN.md
tags:
- String
- Simulation
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: 困难
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3615.Longest%20Palindromic%20Path%20in%20Graph/README.md
tags:
- 位运算
- 图
- 字符串
- 动态规划
---

<!-- problem:start -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
comments: true
difficulty: Hard
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3615.Longest%20Palindromic%20Path%20in%20Graph/README_EN.md
tags:
- Bit Manipulation
- Graph
- String
- Dynamic Programming
---

<!-- problem:start -->
Expand Down
Loading