Skip to content

Commit 4560d6c

Browse files
committed
test: [20250712] Add (1900)
1 parent 5fffed5 commit 4560d6c

File tree

13 files changed

+228
-34
lines changed

13 files changed

+228
-34
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ members = [
253253
"problems/problems_3439",
254254
"problems/problems_3440",
255255
"problems/problems_3169",
256+
"problems/problems_1900",
256257
]
257258

258259
[package]
@@ -528,3 +529,4 @@ solution_1751 = { path = "problems/problems_1751", features = ["solution_1751"]
528529
solution_3439 = { path = "problems/problems_3439", features = ["solution_3439"] }
529530
solution_3440 = { path = "problems/problems_3440", features = ["solution_3440"] }
530531
solution_3169 = { path = "problems/problems_3169", features = ["solution_3169"] }
532+
solution_1900 = { path = "problems/problems_1900", features = ["solution_1900"] }

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "3169",
2+
"daily": "1900",
33
"plans": ["3602", "problems", "3603", "problems", "3604", "problems", "3605", "problems", "3606", "problems", "3607", "problems", "3608", "problems", "3609", "problems"]
44
}

golang/solution_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package golang
22

33
import (
4-
problem "leetCode/problems/problems_3169"
4+
problem "leetCode/problems/problems_1900"
55
"testing"
66
)
77

88
func TestSolution(t *testing.T) {
9-
TestEach(t, "3169", "problems", problem.Solve)
9+
TestEach(t, "1900", "problems", problem.Solve)
1010
}

problems/problems_1900/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "solution_1900"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.79.0"
6+
authors = ["benhao"]
7+
description = "LeetCode Solution 1900 in Rust"
8+
readme = "../../README.md"
9+
10+
[features]
11+
solution_1900 = []
12+
13+
[dependencies]
14+
serde_json = "1.0"
15+
rand = "0.8.4"
16+
regex = "1.10.5"
17+
library = { path = "../../rust/library", features = ["model"] }
18+
19+
[lib]
20+
name = "solution_1900"
21+
path = "solution.rs"

problems/problems_1900/Solution.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//go:build ignore
2+
#include "cpp/common/Solution.h"
3+
4+
5+
using namespace std;
6+
using json = nlohmann::json;
7+
8+
class Solution {
9+
public:
10+
vector<int> earliestAndLatest(int n, int firstPlayer, int secondPlayer) {
11+
12+
}
13+
};
14+
15+
json leetcode::qubh::Solve(string input_json_values) {
16+
vector<string> inputArray;
17+
size_t pos = input_json_values.find('\n');
18+
while (pos != string::npos) {
19+
inputArray.push_back(input_json_values.substr(0, pos));
20+
input_json_values = input_json_values.substr(pos + 1);
21+
pos = input_json_values.find('\n');
22+
}
23+
inputArray.push_back(input_json_values);
24+
25+
Solution solution;
26+
int n = json::parse(inputArray.at(0));
27+
int firstPlayer = json::parse(inputArray.at(1));
28+
int secondPlayer = json::parse(inputArray.at(2));
29+
return solution.earliestAndLatest(n, firstPlayer, secondPlayer);
30+
}

problems/problems_1900/Solution.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package problems.problems_1900;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import java.util.*;
5+
import qubhjava.BaseSolution;
6+
7+
8+
public class Solution extends BaseSolution {
9+
public int[] earliestAndLatest(int n, int firstPlayer, int secondPlayer) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
int n = Integer.parseInt(inputJsonValues[0]);
16+
int firstPlayer = Integer.parseInt(inputJsonValues[1]);
17+
int secondPlayer = Integer.parseInt(inputJsonValues[2]);
18+
return JSON.toJSON(earliestAndLatest(n, firstPlayer, secondPlayer));
19+
}
20+
}

problems/problems_1900/problem.md

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
# 1900. The Earliest and Latest Rounds Where Players Compete [Rating: 2454.77]
22

3-
There is a tournament where `n` players are participating. The players are standing in a single row and are numbered from `1` to `n` based on their **initial**standing position (player `1` is the first player in the row, player `2` is the second player in the row, etc.).
3+
<p>There is a tournament where <code>n</code> players are participating. The players are standing in a single row and are numbered from <code>1</code> to <code>n</code> based on their <strong>initial</strong> standing position (player <code>1</code> is the first player in the row, player <code>2</code> is the second player in the row, etc.).</p>
44

5-
The tournament consists of multiple rounds (starting from round number `1`). In each round, the `ith` player from the front of the row competes against the `ith` player from the end of the row, and the winner advances to the next round. When the number of players is odd for the current round, the player in the middle automatically advances to the next round.
5+
<p>The tournament consists of multiple rounds (starting from round number <code>1</code>). In each round, the <code>i<sup>th</sup></code> player from the front of the row competes against the <code>i<sup>th</sup></code> player from the end of the row, and the winner advances to the next round. When the number of players is odd for the current round, the player in the middle automatically advances to the next round.</p>
66

7-
- For example, if the row consists of players `1, 2, 4, 6, 7`
7+
<ul>
8+
<li>For example, if the row consists of players <code>1, 2, 4, 6, 7</code>
9+
<ul>
10+
<li>Player <code>1</code> competes against player <code>7</code>.</li>
11+
<li>Player <code>2</code> competes against player <code>6</code>.</li>
12+
<li>Player <code>4</code> automatically advances to the next round.</li>
13+
</ul>
14+
</li>
15+
</ul>
816

9-
- Player `1` competes against player `7`.
10-
- Player `2` competes against player `6`.
11-
- Player `4` automatically advances to the next round.
17+
<p>After each round is over, the winners are lined back up in the row based on the <strong>original ordering</strong> assigned to them initially (ascending order).</p>
1218

13-
After each round is over, the winners are lined back up in the row based on the **original ordering** assigned to them initially (ascending order).
19+
<p>The players numbered <code>firstPlayer</code> and <code>secondPlayer</code> are the best in the tournament. They can win against any other player before they compete against each other. If any two other players compete against each other, either of them might win, and thus you may <strong>choose</strong> the outcome of this round.</p>
1420

15-
The players numbered `firstPlayer` and `secondPlayer` are the best in the tournament. They can win against any other player before they compete against each other. If any two other players compete against each other, either of them might win, and thus you may **choose** the outcome of this round.
21+
<p>Given the integers <code>n</code>, <code>firstPlayer</code>, and <code>secondPlayer</code>, return <em>an integer array containing two values, the <strong>earliest</strong> possible round number and the&nbsp;<strong>latest</strong> possible round number in which these two players will compete against each other, respectively</em>.</p>
1622

17-
Given the integers `n`, `firstPlayer`, and `secondPlayer`, return *an integer array containing two values, the **earliest** possible round number and the **latest** possible round number in which these two players will compete against each other, respectively*.
23+
<p>&nbsp;</p>
24+
<p><strong class="example">Example 1:</strong></p>
1825

19-
20-
21-
**Example 1:**
22-
23-
```
24-
Input: n = 11, firstPlayer = 2, secondPlayer = 4
25-
Output: [3,4]
26-
Explanation:
26+
<pre>
27+
<strong>Input:</strong> n = 11, firstPlayer = 2, secondPlayer = 4
28+
<strong>Output:</strong> [3,4]
29+
<strong>Explanation:</strong>
2730
One possible scenario which leads to the earliest round number:
2831
First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
2932
Second round: 2, 3, 4, 5, 6, 11
@@ -33,20 +36,21 @@ First round: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
3336
Second round: 1, 2, 3, 4, 5, 6
3437
Third round: 1, 2, 4
3538
Fourth round: 2, 4
36-
```
39+
</pre>
3740

38-
**Example 2:**
41+
<p><strong class="example">Example 2:</strong></p>
3942

40-
```
41-
Input: n = 5, firstPlayer = 1, secondPlayer = 5
42-
Output: [1,1]
43-
Explanation: The players numbered 1 and 5 compete in the first round.
43+
<pre>
44+
<strong>Input:</strong> n = 5, firstPlayer = 1, secondPlayer = 5
45+
<strong>Output:</strong> [1,1]
46+
<strong>Explanation:</strong> The players numbered 1 and 5 compete in the first round.
4447
There is no way to make them compete in any other round.
45-
```
46-
47-
48+
</pre>
4849

49-
**Constraints:**
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
5052

51-
- `2 <= n <= 28`
52-
- `1 <= firstPlayer < secondPlayer <= n`
53+
<ul>
54+
<li><code>2 &lt;= n &lt;= 28</code></li>
55+
<li><code>1 &lt;= firstPlayer &lt; secondPlayer &lt;= n</code></li>
56+
</ul>

problems/problems_1900/problem_zh.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# 1900. 最佳运动员的比拼回合 [难度分: 2454.77]
2+
3+
<p><code>n</code> 名运动员参与一场锦标赛,所有运动员站成一排,并根据 <strong>最开始的</strong> 站位从 <code>1</code> 到 <code>n</code> 编号(运动员 <code>1</code> 是这一排中的第一个运动员,运动员 <code>2</code> 是第二个运动员,依此类推)。</p>
4+
5+
<p>锦标赛由多个回合组成(从回合 <code>1</code> 开始)。每一回合中,这一排从前往后数的第 <code>i</code> 名运动员需要与从后往前数的第 <code>i</code> 名运动员比拼,获胜者将会进入下一回合。如果当前回合中运动员数目为奇数,那么中间那位运动员将轮空晋级下一回合。</p>
6+
7+
<ul>
8+
<li>例如,当前回合中,运动员 <code>1, 2, 4, 6, 7</code> 站成一排
9+
<ul>
10+
<li>运动员 <code>1</code> 需要和运动员 <code>7</code> 比拼</li>
11+
<li>运动员 <code>2</code> 需要和运动员 <code>6</code> 比拼</li>
12+
<li>运动员 <code>4</code> 轮空晋级下一回合</li>
13+
</ul>
14+
</li>
15+
</ul>
16+
17+
<p>每回合结束后,获胜者将会基于最开始分配给他们的原始顺序(升序)重新排成一排。</p>
18+
19+
<p>编号为 <code>firstPlayer</code> 和 <code>secondPlayer</code> 的运动员是本场锦标赛中的最佳运动员。在他们开始比拼之前,完全可以战胜任何其他运动员。而任意两个其他运动员进行比拼时,其中任意一个都有获胜的可能,因此你可以 <strong>裁定</strong> 谁是这一回合的获胜者。</p>
20+
21+
<p>给你三个整数 <code>n</code>、<code>firstPlayer</code> 和 <code>secondPlayer</code> 。返回一个由两个值组成的整数数组,分别表示两位最佳运动员在本场锦标赛中比拼的 <strong>最早</strong> 回合数和 <strong>最晚</strong> 回合数。</p>
22+
23+
<p> </p>
24+
25+
<p><strong>示例 1:</strong></p>
26+
27+
<pre><strong>输入:</strong>n = 11, firstPlayer = 2, secondPlayer = 4
28+
<strong>输出:</strong>[3,4]
29+
<strong>解释:</strong>
30+
一种能够产生最早回合数的情景是:
31+
回合 1:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
32+
回合 2:2, 3, 4, 5, 6, 11
33+
回合 3:2, 3, 4
34+
一种能够产生最晚回合数的情景是:
35+
回合 1:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
36+
回合 2:1, 2, 3, 4, 5, 6
37+
回合 3:1, 2, 4
38+
回合 4:2, 4
39+
</pre>
40+
41+
<p><strong>示例 2:</strong></p>
42+
43+
<pre><strong>输入:</strong>n = 5, firstPlayer = 1, secondPlayer = 5
44+
<strong>输出:</strong>[1,1]
45+
<strong>解释:</strong>两名最佳运动员 1 和 5 将会在回合 1 进行比拼。
46+
不存在使他们在其他回合进行比拼的可能。
47+
</pre>
48+
49+
<p> </p>
50+
51+
<p><strong>提示:</strong></p>
52+
53+
<ul>
54+
<li><code>2 &lt;= n &lt;= 28</code></li>
55+
<li><code>1 &lt;= firstPlayer &lt; secondPlayer &lt;= n</code></li>
56+
</ul>

problems/problems_1900/solution.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package problem1900
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"strings"
7+
)
8+
9+
func earliestAndLatest(n int, firstPlayer int, secondPlayer int) []int {
10+
11+
}
12+
13+
func Solve(inputJsonValues string) any {
14+
inputValues := strings.Split(inputJsonValues, "\n")
15+
var n int
16+
var firstPlayer int
17+
var secondPlayer int
18+
19+
if err := json.Unmarshal([]byte(inputValues[0]), &n); err != nil {
20+
log.Fatal(err)
21+
}
22+
if err := json.Unmarshal([]byte(inputValues[1]), &firstPlayer); err != nil {
23+
log.Fatal(err)
24+
}
25+
if err := json.Unmarshal([]byte(inputValues[2]), &secondPlayer); err != nil {
26+
log.Fatal(err)
27+
}
28+
29+
return earliestAndLatest(n, firstPlayer, secondPlayer)
30+
}

problems/problems_1900/solution.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use serde_json::{json, Value};
2+
3+
pub struct Solution;
4+
5+
impl Solution {
6+
pub fn earliest_and_latest(n: i32, first_player: i32, second_player: i32) -> Vec<i32> {
7+
8+
}
9+
}
10+
11+
#[cfg(feature = "solution_1900")]
12+
pub fn solve(input_string: String) -> Value {
13+
let input_values: Vec<String> = input_string.split('\n').map(|x| x.to_string()).collect();
14+
let n: i32 = serde_json::from_str(&input_values[0]).expect("Failed to parse input");
15+
let first_player: i32 = serde_json::from_str(&input_values[1]).expect("Failed to parse input");
16+
let second_player: i32 = serde_json::from_str(&input_values[2]).expect("Failed to parse input");
17+
json!(Solution::earliest_and_latest(n, first_player, second_player))
18+
}

0 commit comments

Comments
 (0)