mirror of https://github.com/doocs/leetcode.git
feat: add solutions to lc problems: No.3201,3202 (#4571)
* No.3201.Find the Maximum Length of Valid Subsequence I * No.3202.Find the Maximum Length of Valid Subsequence II
This commit is contained in:
parent
97d7b82143
commit
47cb088abc
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -24,13 +24,13 @@ tags:
|
|||
|
||||
<p>另外给你一个二维整数数组 <code>waitCost</code>,其中 <code>waitCost[i][j]</code> 定义了在该单元格 <strong>等待 </strong>的成本。</p>
|
||||
|
||||
<p>你从第 1 秒开始在单元格 <code>(0, 0)</code>。</p>
|
||||
<p>路径始终从第 1 步进入单元格 <code>(0, 0)</code> 并支付入场花费开始。</p>
|
||||
|
||||
<p>每一步,你都遵循交替模式:</p>
|
||||
|
||||
<ul>
|
||||
<li>在 <strong>奇数秒 </strong>,你必须向 <strong>右 </strong>或向 <strong>下 </strong>移动到 <strong>相邻 </strong>的单元格,并支付其进入成本。</li>
|
||||
<li>在 <strong>偶数秒 </strong>,你必须原地 <strong>等待 </strong>,并支付 <code>waitCost[i][j]</code>。</li>
|
||||
<li>在 <strong>偶数秒 </strong>,你必须原地 <strong>等待</strong><strong>恰好</strong> 1 秒并在 1 秒期间支付 <code>waitCost[i][j]</code>。</li>
|
||||
</ul>
|
||||
|
||||
<p>返回到达 <code>(m - 1, n - 1)</code> 所需的 <strong>最小 </strong>总成本。</p>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -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 -->
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3616.Nu
|
|||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3616. Number of Student Replacements 🔒](https://leetcode.cn/problems/number-of-student-replacements)
|
||||
# [3616. 学生替换人数 🔒](https://leetcode.cn/problems/number-of-student-replacements)
|
||||
|
||||
[English Version](/solution/3600-3699/3616.Number%20of%20Student%20Replacements/README_EN.md)
|
||||
|
||||
|
|
@ -14,53 +14,55 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3616.Nu
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>You are given an integer array <code>ranks</code> where <code>ranks[i]</code> represents the rank of the <code>i<sup>th</sup></code> student arriving <strong>in order</strong>. A lower number indicates a <strong>better</strong> rank.</p>
|
||||
<p>给定一个整数数组 <code>ranks</code>,其中 <code>ranks[i]</code> 表示第 <code>i</code> 个 <strong>按顺序</strong> 到达的学生排名。数字越低表示排名 <strong>越好</strong>。</p>
|
||||
|
||||
<p>Initially, the first student is <strong>selected</strong> by default.</p>
|
||||
<p>最初,默认 <strong>选中</strong> 第一个学生。</p>
|
||||
|
||||
<p>A <strong>replacement</strong> occurs when a student with a <strong>strictly</strong> better rank arrives and <strong>replaces</strong> the current selection.</p>
|
||||
<p>当一名排名 <strong>严格</strong> 更好的学生到来时,会发生 <strong>替换</strong>,并 <strong>取代</strong> 当前的选择。</p>
|
||||
|
||||
<p>Return the total number of replacements made.</p>
|
||||
<p>返回替换的总数。</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<p><strong class="example">示例 1:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">ranks = [4,1,2]</span></p>
|
||||
<p><span class="example-io"><b>输入:</b>ranks = [4,1,2]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">1</span></p>
|
||||
<p><span class="example-io"><b>输出:</b>1</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The first student with <code>ranks[0] = 4</code> is initially selected.</li>
|
||||
<li>The second student with <code>ranks[1] = 1</code> is better than the current selection, so a replacement occurs.</li>
|
||||
<li>The third student has a worse rank, so no replacement occurs.</li>
|
||||
<li>Thus, the number of replacements is 1.</li>
|
||||
<li>第一个 <code>ranks[0] = 4</code> 的学生最初被选中。</li>
|
||||
<li>第二个学生 <code>ranks[1] = 1</code> 比当前选择更好,因此发生替换。</li>
|
||||
<li>第三名学生排名更差,因此没有发生替换。</li>
|
||||
<li>因此,替换的人数为 1。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
<p><strong class="example">示例 2:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">ranks = [2,2,3]</span></p>
|
||||
<p><span class="example-io"><b>输入:</b>ranks = [2,2,3]</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">0</span></p>
|
||||
<p><strong>输出:</strong><span class="example-io">0</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>The first student with <code>ranks[0] = 2</code> is initially selected.</li>
|
||||
<li>Neither of <code>ranks[1] = 2</code> or <code>ranks[2] = 3</code> is better than the current selection.</li>
|
||||
<li>Thus, the number of replacements is 0.</li>
|
||||
<li>第一个 <code>ranks[0] = 2</code> 的学生最初被选中。</li>
|
||||
<li>两个 <code>ranks[1] = 2</code> 或 <code>ranks[2] = 3</code> 都不如当前选择好。</li>
|
||||
<li>因此,替换的人数为 0。</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= ranks.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= ranks.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>1 <= ranks[i] <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ tags:
|
|||
|
||||
<!-- problem:start -->
|
||||
|
||||
# [3617. Find Students with Study Spiral Pattern](https://leetcode.cn/problems/find-students-with-study-spiral-pattern)
|
||||
# [3617. 查找具有螺旋学习模式的学生](https://leetcode.cn/problems/find-students-with-study-spiral-pattern)
|
||||
|
||||
[English Version](/solution/3600-3699/3617.Find%20Students%20with%20Study%20Spiral%20Pattern/README_EN.md)
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ tags:
|
|||
|
||||
<!-- description:start -->
|
||||
|
||||
<p>Table: <code>students</code></p>
|
||||
<p>表:<code>students</code></p>
|
||||
|
||||
<pre>
|
||||
+--------------+---------+
|
||||
|
|
@ -26,11 +26,11 @@ tags:
|
|||
| student_name | varchar |
|
||||
| major | varchar |
|
||||
+--------------+---------+
|
||||
student_id is the unique identifier for this table.
|
||||
Each row contains information about a student and their academic major.
|
||||
student_id 是这张表的唯一主键。
|
||||
每一行包含有关学生及其学术专业的信息。
|
||||
</pre>
|
||||
|
||||
<p>Table: <code>study_sessions</code></p>
|
||||
<p>表:<code>study_sessions</code></p>
|
||||
|
||||
<pre>
|
||||
+---------------+---------+
|
||||
|
|
@ -42,32 +42,33 @@ Each row contains information about a student and their academic major.
|
|||
| session_date | date |
|
||||
| hours_studied | decimal |
|
||||
+---------------+---------+
|
||||
session_id is the unique identifier for this table.
|
||||
Each row represents a study session by a student for a specific subject.
|
||||
session_id 是这张表的唯一主键。
|
||||
每一行代表一个学生针对特定学科的学习时段。
|
||||
</pre>
|
||||
|
||||
<p>Write a solution to find students who follow the <strong>Study Spiral Pattern</strong> - students who consistently study multiple subjects in a rotating cycle.</p>
|
||||
<p>编写一个解决方案来找出遵循 <strong>螺旋学习模式</strong> 的学生——即那些持续学习多个学科并按循环周期进行学习的学生。</p>
|
||||
|
||||
<ul>
|
||||
<li>A Study Spiral Pattern means a student studies at least <code>3</code><strong> different subjects</strong> in a repeating sequence</li>
|
||||
<li>The pattern must repeat for <strong>at least </strong><code>2</code><strong> complete cycles</strong> (minimum <code>6</code> study sessions)</li>
|
||||
<li>Sessions must be <strong>consecutive dates</strong> with no gaps longer than <code>2</code> days between sessions</li>
|
||||
<li>Calculate the <strong>cycle length</strong> (number of different subjects in the pattern)</li>
|
||||
<li>Calculate the <strong>total study hours</strong> across all sessions in the pattern</li>
|
||||
<li>Only include students with cycle length of <strong>at least </strong><code>3</code><strong> subjects</strong></li>
|
||||
<li>螺旋学习模式意味着学生以重复的顺序学习至少 <code>3</code> 个 <strong>不同的学科</strong>。</li>
|
||||
<li>模式必须重复 <strong>至少</strong><strong> </strong><code>2</code><strong> 个完整周期</strong>(最少 <code>6</code> 次学习记录)。</li>
|
||||
<li>两次学习记录必须是间隔不超过 <code>2</code> 天的 <strong>连续日期</strong>。</li>
|
||||
<li>计算 <strong>循环长度</strong>(模式中不同的学科数量)。</li>
|
||||
<li>计算模式中所有学习记录的 <strong>总学习时长</strong>。</li>
|
||||
<li>仅包含循环长度 <strong>至少为 </strong><strong> </strong><code>3</code><strong> 门学科</strong> 的学生。</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the result table ordered by cycle length in <strong>descending</strong> order, then by total study hours in <strong>descending</strong> order</em>.</p>
|
||||
<p>返回结果表按循环长度 <strong>降序</strong> 排序,然后按总学习时间 <strong>降序</strong> 排序。</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
<p>结果格式如下所示。</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example:</strong></p>
|
||||
|
||||
<p><strong class="example">示例:</strong></p>
|
||||
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong></p>
|
||||
<p><strong>输入:</strong></p>
|
||||
|
||||
<p>students table:</p>
|
||||
<p>students 表:</p>
|
||||
|
||||
<pre class="example-io">
|
||||
+------------+--------------+------------------+
|
||||
|
|
@ -81,7 +82,7 @@ Each row represents a study session by a student for a specific subject.
|
|||
+------------+--------------+------------------+
|
||||
</pre>
|
||||
|
||||
<p>study_sessions table:</p>
|
||||
<p>study_sessions 表:</p>
|
||||
|
||||
<pre class="example-io">
|
||||
+------------+------------+------------+--------------+---------------+
|
||||
|
|
@ -110,7 +111,7 @@ Each row represents a study session by a student for a specific subject.
|
|||
+------------+------------+------------+--------------+---------------+
|
||||
</pre>
|
||||
|
||||
<p><strong>Output:</strong></p>
|
||||
<p><strong>输出:</strong></p>
|
||||
|
||||
<pre class="example-io">
|
||||
+------------+--------------+------------------+--------------+-------------------+
|
||||
|
|
@ -121,39 +122,39 @@ Each row represents a study session by a student for a specific subject.
|
|||
+------------+--------------+------------------+--------------+-------------------+
|
||||
</pre>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
<p><strong>解释:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><strong>Alice Chen (student_id = 1):</strong>
|
||||
|
||||
<ul>
|
||||
<li>Study sequence: Math → Physics → Chemistry → Math → Physics → Chemistry</li>
|
||||
<li>Pattern: 3 subjects (Math, Physics, Chemistry) repeating for 2 complete cycles</li>
|
||||
<li>Consecutive dates: Oct 1-6 with no gaps > 2 days</li>
|
||||
<li>Cycle length: 3 subjects</li>
|
||||
<li>Total hours: 2.5 + 3.0 + 2.0 + 2.5 + 3.0 + 2.0 = 15.0 hours</li>
|
||||
<li>学习序列:Math → Physics → Chemistry → Math → Physics → Chemistry</li>
|
||||
<li>模式:3 门学科(Math,Physics,Chemistry)重复 2 个完整周期</li>
|
||||
<li>连续日期:十月 1-6,没有超过 2 天的间隔</li>
|
||||
<li>循环长度:3 门学科</li>
|
||||
<li>总时间:2.5 + 3.0 + 2.0 + 2.5 + 3.0 + 2.0 = 15.0 小时</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><strong>Bob Johnson (student_id = 2):</strong>
|
||||
<ul>
|
||||
<li>Study sequence: Algebra → Calculus → Statistics → Geometry → Algebra → Calculus → Statistics → Geometry</li>
|
||||
<li>Pattern: 4 subjects (Algebra, Calculus, Statistics, Geometry) repeating for 2 complete cycles</li>
|
||||
<li>Consecutive dates: Oct 1-8 with no gaps > 2 days</li>
|
||||
<li>Cycle length: 4 subjects</li>
|
||||
<li>Total hours: 4.0 + 3.5 + 2.5 + 3.0 + 4.0 + 3.5 + 2.5 + 3.0 = 26.0 hours</li>
|
||||
<li>学习序列:Algebra → Calculus → Statistics → Geometry → Algebra → Calculus → Statistics → Geometry</li>
|
||||
<li>模式:4 门学科(Algebra,Calculus,Statistics,Geometry)重复 2 个完整周期</li>
|
||||
<li>连续日期:十月 1-8,没有超过 2 天的间隔</li>
|
||||
<li>循环长度:4 门学科</li>
|
||||
<li>总时间:4.0 + 3.5 + 2.5 + 3.0 + 4.0 + 3.5 + 2.5 + 3.0 = 26.0 小时</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><strong>Students not included:</strong>
|
||||
<li><strong>未包含学生:</strong>
|
||||
<ul>
|
||||
<li>Carol Davis (student_id = 3): Only 2 subjects (Biology, Chemistry) - doesn't meet minimum 3 subjects requirement</li>
|
||||
<li>David Wilson (student_id = 4): Only 2 study sessions with a 4-day gap - doesn't meet consecutive dates requirement</li>
|
||||
<li>Emma Brown (student_id = 5): No study sessions recorded</li>
|
||||
<li>Carol Davis (student_id = 3):仅 2 门学科(生物,化学)- 未满足至少 3 门学科的要求</li>
|
||||
<li>David Wilson (student_id = 4):仅 2 次学习课程,间隔 4 天 - 不符合连续日期要求</li>
|
||||
<li>Emma Brown (student_id = 5):没有记录学习课程</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>The result table is ordered by cycle_length in descending order, then by total_study_hours in descending order.</p>
|
||||
<p>结果表以 cycle_length 降序排序,然后以 total_study_hours 降序排序。</p>
|
||||
</div>
|
||||
|
||||
<!-- description:end -->
|
||||
|
|
@ -299,7 +300,8 @@ WITH
|
|||
SUBSTRING_INDEX(SUBSTRING_INDEX(subject_sequence, ',', 6), ',', -3),
|
||||
'%'
|
||||
)
|
||||
OR subject_sequence LIKE CONCAT( -- 匹配4科循环2轮的模式
|
||||
OR subject_sequence LIKE CONCAT(
|
||||
-- 匹配4科循环2轮的模式
|
||||
SUBSTRING_INDEX(subject_sequence, ',', 4),
|
||||
',',
|
||||
SUBSTRING_INDEX(SUBSTRING_INDEX(subject_sequence, ',', 8), ',', -4),
|
||||
|
|
|
|||
|
|
@ -321,8 +321,8 @@
|
|||
| 3580 | [寻找持续进步的员工](/solution/3500-3599/3580.Find%20Consistently%20Improving%20Employees/README.md) | `数据库` | 中等 | |
|
||||
| 3586 | [寻找 COVID 康复患者](/solution/3500-3599/3586.Find%20COVID%20Recovery%20Patients/README.md) | `数据库` | 中等 | |
|
||||
| 3601 | [寻找燃油效率提升的驾驶员](/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README.md) | `数据库` | 中等 | |
|
||||
| 3611 | [查找超预订员工](/solution/3600-3699/3611.Find%20Overbooked%20Employees/README.md) | | 中等 | |
|
||||
| 3617 | [Find Students with Study Spiral Pattern](/solution/3600-3699/3617.Find%20Students%20with%20Study%20Spiral%20Pattern/README.md) | | 困难 | |
|
||||
| 3611 | [查找超预订员工](/solution/3600-3699/3611.Find%20Overbooked%20Employees/README.md) | `数据库` | 中等 | |
|
||||
| 3617 | [查找具有螺旋学习模式的学生](/solution/3600-3699/3617.Find%20Students%20with%20Study%20Spiral%20Pattern/README.md) | | 困难 | |
|
||||
|
||||
## 版权
|
||||
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 3580 | [Find Consistently Improving Employees](/solution/3500-3599/3580.Find%20Consistently%20Improving%20Employees/README_EN.md) | `Database` | Medium | |
|
||||
| 3586 | [Find COVID Recovery Patients](/solution/3500-3599/3586.Find%20COVID%20Recovery%20Patients/README_EN.md) | `Database` | Medium | |
|
||||
| 3601 | [Find Drivers with Improved Fuel Efficiency](/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README_EN.md) | `Database` | Medium | |
|
||||
| 3611 | [Find Overbooked Employees](/solution/3600-3699/3611.Find%20Overbooked%20Employees/README_EN.md) | | Medium | |
|
||||
| 3611 | [Find Overbooked Employees](/solution/3600-3699/3611.Find%20Overbooked%20Employees/README_EN.md) | `Database` | Medium | |
|
||||
| 3617 | [Find Students with Study Spiral Pattern](/solution/3600-3699/3617.Find%20Students%20with%20Study%20Spiral%20Pattern/README_EN.md) | | Hard | |
|
||||
|
||||
## Copyright
|
||||
|
|
|
|||
|
|
@ -3621,13 +3621,13 @@
|
|||
| 3608 | [包含 K 个连通分量需要的最小时间](/solution/3600-3699/3608.Minimum%20Time%20for%20K%20Connected%20Components/README.md) | `并查集`,`图`,`二分查找`,`排序` | 中等 | 第 457 场周赛 |
|
||||
| 3609 | [到达目标点的最小移动次数](/solution/3600-3699/3609.Minimum%20Moves%20to%20Reach%20Target%20in%20Grid/README.md) | `数学` | 困难 | 第 457 场周赛 |
|
||||
| 3610 | [目标和所需的最小质数个数](/solution/3600-3699/3610.Minimum%20Number%20of%20Primes%20to%20Sum%20to%20Target/README.md) | | 中等 | 🔒 |
|
||||
| 3611 | [查找超预订员工](/solution/3600-3699/3611.Find%20Overbooked%20Employees/README.md) | | 中等 | |
|
||||
| 3612 | [用特殊操作处理字符串 I](/solution/3600-3699/3612.Process%20String%20with%20Special%20Operations%20I/README.md) | | 中等 | 第 458 场周赛 |
|
||||
| 3613 | [最小化连通分量的最大成本](/solution/3600-3699/3613.Minimize%20Maximum%20Component%20Cost/README.md) | | 中等 | 第 458 场周赛 |
|
||||
| 3614 | [用特殊操作处理字符串 II](/solution/3600-3699/3614.Process%20String%20with%20Special%20Operations%20II/README.md) | | 困难 | 第 458 场周赛 |
|
||||
| 3615 | [图中的最长回文路径](/solution/3600-3699/3615.Longest%20Palindromic%20Path%20in%20Graph/README.md) | | 困难 | 第 458 场周赛 |
|
||||
| 3616 | [Number of Student Replacements](/solution/3600-3699/3616.Number%20of%20Student%20Replacements/README.md) | | 中等 | 🔒 |
|
||||
| 3617 | [Find Students with Study Spiral Pattern](/solution/3600-3699/3617.Find%20Students%20with%20Study%20Spiral%20Pattern/README.md) | | 困难 | |
|
||||
| 3611 | [查找超预订员工](/solution/3600-3699/3611.Find%20Overbooked%20Employees/README.md) | `数据库` | 中等 | |
|
||||
| 3612 | [用特殊操作处理字符串 I](/solution/3600-3699/3612.Process%20String%20with%20Special%20Operations%20I/README.md) | `字符串`,`模拟` | 中等 | 第 458 场周赛 |
|
||||
| 3613 | [最小化连通分量的最大成本](/solution/3600-3699/3613.Minimize%20Maximum%20Component%20Cost/README.md) | `排序`,`并查集`,`图`,`二分查找` | 中等 | 第 458 场周赛 |
|
||||
| 3614 | [用特殊操作处理字符串 II](/solution/3600-3699/3614.Process%20String%20with%20Special%20Operations%20II/README.md) | `字符串`,`模拟` | 困难 | 第 458 场周赛 |
|
||||
| 3615 | [图中的最长回文路径](/solution/3600-3699/3615.Longest%20Palindromic%20Path%20in%20Graph/README.md) | `位运算`,`图`,`字符串`,`动态规划` | 困难 | 第 458 场周赛 |
|
||||
| 3616 | [学生替换人数](/solution/3600-3699/3616.Number%20of%20Student%20Replacements/README.md) | | 中等 | 🔒 |
|
||||
| 3617 | [查找具有螺旋学习模式的学生](/solution/3600-3699/3617.Find%20Students%20with%20Study%20Spiral%20Pattern/README.md) | | 困难 | |
|
||||
|
||||
## 版权
|
||||
|
||||
|
|
|
|||
|
|
@ -3619,11 +3619,11 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
|
|||
| 3608 | [Minimum Time for K Connected Components](/solution/3600-3699/3608.Minimum%20Time%20for%20K%20Connected%20Components/README_EN.md) | `Union Find`,`Graph`,`Binary Search`,`Sorting` | Medium | Weekly Contest 457 |
|
||||
| 3609 | [Minimum Moves to Reach Target in Grid](/solution/3600-3699/3609.Minimum%20Moves%20to%20Reach%20Target%20in%20Grid/README_EN.md) | `Math` | Hard | Weekly Contest 457 |
|
||||
| 3610 | [Minimum Number of Primes to Sum to Target](/solution/3600-3699/3610.Minimum%20Number%20of%20Primes%20to%20Sum%20to%20Target/README_EN.md) | | Medium | 🔒 |
|
||||
| 3611 | [Find Overbooked Employees](/solution/3600-3699/3611.Find%20Overbooked%20Employees/README_EN.md) | | Medium | |
|
||||
| 3612 | [Process String with Special Operations I](/solution/3600-3699/3612.Process%20String%20with%20Special%20Operations%20I/README_EN.md) | | Medium | Weekly Contest 458 |
|
||||
| 3613 | [Minimize Maximum Component Cost](/solution/3600-3699/3613.Minimize%20Maximum%20Component%20Cost/README_EN.md) | | Medium | Weekly Contest 458 |
|
||||
| 3614 | [Process String with Special Operations II](/solution/3600-3699/3614.Process%20String%20with%20Special%20Operations%20II/README_EN.md) | | Hard | Weekly Contest 458 |
|
||||
| 3615 | [Longest Palindromic Path in Graph](/solution/3600-3699/3615.Longest%20Palindromic%20Path%20in%20Graph/README_EN.md) | | Hard | Weekly Contest 458 |
|
||||
| 3611 | [Find Overbooked Employees](/solution/3600-3699/3611.Find%20Overbooked%20Employees/README_EN.md) | `Database` | Medium | |
|
||||
| 3612 | [Process String with Special Operations I](/solution/3600-3699/3612.Process%20String%20with%20Special%20Operations%20I/README_EN.md) | `String`,`Simulation` | Medium | Weekly Contest 458 |
|
||||
| 3613 | [Minimize Maximum Component Cost](/solution/3600-3699/3613.Minimize%20Maximum%20Component%20Cost/README_EN.md) | `Sort`,`Union Find`,`Graph`,`Binary Search` | Medium | Weekly Contest 458 |
|
||||
| 3614 | [Process String with Special Operations II](/solution/3600-3699/3614.Process%20String%20with%20Special%20Operations%20II/README_EN.md) | `String`,`Simulation` | Hard | Weekly Contest 458 |
|
||||
| 3615 | [Longest Palindromic Path in Graph](/solution/3600-3699/3615.Longest%20Palindromic%20Path%20in%20Graph/README_EN.md) | `Bit Manipulation`,`Graph`,`String`,`Dynamic Programming` | Hard | Weekly Contest 458 |
|
||||
| 3616 | [Number of Student Replacements](/solution/3600-3699/3616.Number%20of%20Student%20Replacements/README_EN.md) | | Medium | 🔒 |
|
||||
| 3617 | [Find Students with Study Spiral Pattern](/solution/3600-3699/3617.Find%20Students%20with%20Study%20Spiral%20Pattern/README_EN.md) | | Hard | |
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue