Skip to content

Commit 88b5e66

Browse files
committed
test: [20250912] Add (3227)
1 parent 839467b commit 88b5e66

File tree

15 files changed

+258
-5
lines changed

15 files changed

+258
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ members = [
315315
"problems/problems_2327",
316316
"problems/problems_1733",
317317
"problems/problems_2785",
318+
"problems/problems_3227",
318319
]
319320

320321
[package]
@@ -652,3 +653,4 @@ solution_1317 = { path = "problems/problems_1317", features = ["solution_1317"]
652653
solution_2327 = { path = "problems/problems_2327", features = ["solution_2327"] }
653654
solution_1733 = { path = "problems/problems_1733", features = ["solution_1733"] }
654655
solution_2785 = { path = "problems/problems_2785", features = ["solution_2785"] }
656+
solution_3227 = { path = "problems/problems_3227", features = ["solution_3227"] }

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "952",
2+
"daily": "3227",
33
"plans": ["3674", "problems", "3675", "problems", "3676", "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_952"
4+
problem "leetCode/problems/problems_3227"
55
"testing"
66
)
77

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

problems/problems_3227/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_3227"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.79.0"
6+
authors = ["benhao"]
7+
description = "LeetCode Solution 3227 in Rust"
8+
readme = "../../README.md"
9+
10+
[features]
11+
solution_3227 = []
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_3227"
21+
path = "solution.rs"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
bool doesAliceWin(string s) {
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+
string s = json::parse(inputArray.at(0));
27+
return solution.doesAliceWin(s);
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package problems.problems_3227;
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 boolean doesAliceWin(String s) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
String s = jsonStringToString(inputJsonValues[0]);
16+
return JSON.toJSON(doesAliceWin(s));
17+
}
18+
}

problems/problems_3227/problem.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# 3227. Vowels Game in a String [Rating: 1451.81]
2+
3+
<p>Alice and Bob are playing a game on a string.</p>
4+
5+
<p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p>
6+
7+
<ul>
8+
<li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substring</span> from <code>s</code> that contains an <strong>odd</strong> number of vowels.</li>
9+
<li>On Bob&#39;s turn, he has to remove any <strong>non-empty</strong> <span data-keyword="substring">substring</span> from <code>s</code> that contains an <strong>even</strong> number of vowels.</li>
10+
</ul>
11+
12+
<p>The first player who cannot make a move on their turn loses the game. We assume that both Alice and Bob play <strong>optimally</strong>.</p>
13+
14+
<p>Return <code>true</code> if Alice wins the game, and <code>false</code> otherwise.</p>
15+
16+
<p>The English vowels are: <code>a</code>, <code>e</code>, <code>i</code>, <code>o</code>, and <code>u</code>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong class="example">Example 1:</strong></p>
20+
21+
<div class="example-block">
22+
<p><strong>Input:</strong> <span class="example-io">s = &quot;leetcoder&quot;</span></p>
23+
24+
<p><strong>Output:</strong> <span class="example-io">true</span></p>
25+
26+
<p><strong>Explanation:</strong><br />
27+
Alice can win the game as follows:</p>
28+
29+
<ul>
30+
<li>Alice plays first, she can delete the underlined substring in <code>s = &quot;<u><strong>leetco</strong></u>der&quot;</code> which contains 3 vowels. The resulting string is <code>s = &quot;der&quot;</code>.</li>
31+
<li>Bob plays second, he can delete the underlined substring in <code>s = &quot;<u><strong>d</strong></u>er&quot;</code> which contains 0 vowels. The resulting string is <code>s = &quot;er&quot;</code>.</li>
32+
<li>Alice plays third, she can delete the whole string <code>s = &quot;<strong><u>er</u></strong>&quot;</code> which contains 1 vowel.</li>
33+
<li>Bob plays fourth, since the string is empty, there is no valid play for Bob. So Alice wins the game.</li>
34+
</ul>
35+
</div>
36+
37+
<p><strong class="example">Example 2:</strong></p>
38+
39+
<div class="example-block">
40+
<p><strong>Input:</strong> <span class="example-io">s = &quot;bbcd&quot;</span></p>
41+
42+
<p><strong>Output:</strong> <span class="example-io">false</span></p>
43+
44+
<p><strong>Explanation:</strong><br />
45+
There is no valid play for Alice in her first turn, so Alice loses the game.</p>
46+
</div>
47+
48+
<p>&nbsp;</p>
49+
<p><strong>Constraints:</strong></p>
50+
51+
<ul>
52+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
53+
<li><code>s</code> consists only of lowercase English letters.</li>
54+
</ul>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# 3227. 字符串元音游戏 [难度分: 1451.81]
2+
3+
<p>小红和小明在玩一个字符串元音游戏。</p>
4+
5+
<p>给你一个字符串 <code>s</code>,小红和小明将轮流参与游戏,小红<strong> 先 </strong>开始:</p>
6+
7+
<ul>
8+
<li>在小红的回合,她必须移除 <code>s</code> 中包含 <strong>奇数 </strong>个元音的任意 <strong>非空</strong> <span data-keyword="substring">子字符串</span>。</li>
9+
<li>在小明的回合,他必须移除 <code>s</code> 中包含 <strong>偶数 </strong>个元音的任意 <strong>非空</strong> <span data-keyword="substring">子字符串</span>。</li>
10+
</ul>
11+
12+
<p>第一个无法在其回合内进行移除操作的玩家输掉游戏。假设小红和小明都采取 <strong>最优策略 </strong>。</p>
13+
14+
<p>如果小红赢得游戏,返回 <code>true</code>,否则返回 <code>false</code>。</p>
15+
16+
<p>英文元音字母包括:<code>a</code>, <code>e</code>, <code>i</code>, <code>o</code>, 和 <code>u</code>。</p>
17+
18+
<p>&nbsp;</p>
19+
20+
<p><strong class="example">示例 1:</strong></p>
21+
22+
<div class="example-block">
23+
<p><strong>输入:</strong> <span class="example-io">s = "leetcoder"</span></p>
24+
25+
<p><strong>输出:</strong> <span class="example-io">true</span></p>
26+
27+
<p><strong>解释:</strong><br />
28+
小红可以执行如下移除操作来赢得游戏:</p>
29+
30+
<ul>
31+
<li>小红先手,她可以移除加下划线的子字符串 <code>s = "<u><strong>leetco</strong></u>der"</code>,其中包含 3 个元音。结果字符串为 <code>s = "der"</code>。</li>
32+
<li>小明接着,他可以移除加下划线的子字符串 <code>s = "<u><strong>d</strong></u>er"</code>,其中包含 0 个元音。结果字符串为 <code>s = "er"</code>。</li>
33+
<li>小红再次操作,她可以移除整个字符串 <code>s = "<strong><u>er</u></strong>"</code>,其中包含 1 个元音。</li>
34+
<li>又轮到小明,由于字符串为空,无法执行移除操作,因此小红赢得游戏。</li>
35+
</ul>
36+
</div>
37+
38+
<p><strong class="example">示例 2:</strong></p>
39+
40+
<div class="example-block">
41+
<p><strong>输入:</strong> <span class="example-io">s = "bbcd"</span></p>
42+
43+
<p><strong>输出:</strong> <span class="example-io">false</span></p>
44+
45+
<p><strong>解释:</strong><br />
46+
小红在她的第一回合无法执行移除操作,因此小红输掉了游戏。</p>
47+
</div>
48+
49+
<p>&nbsp;</p>
50+
51+
<p><strong>提示:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
55+
<li><code>s</code> 仅由小写英文字母组成。</li>
56+
</ul>

problems/problems_3227/solution.go

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

problems/problems_3227/solution.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import solution
2+
from typing import *
3+
4+
5+
class Solution(solution.Solution):
6+
def solve(self, test_input=None):
7+
return self.doesAliceWin(test_input)
8+
9+
def doesAliceWin(self, s: str) -> bool:
10+
pass
11+

0 commit comments

Comments
 (0)