Skip to content

Commit 7c43a88

Browse files
committed
test: 3227 solution
py, c++, go, java
1 parent 88b5e66 commit 7c43a88

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
//go:build ignore
22
#include "cpp/common/Solution.h"
3-
3+
#include <algorithm>
44

55
using namespace std;
66
using json = nlohmann::json;
77

8+
constexpr string VOWELS = "aeiou";
9+
810
class Solution {
911
public:
10-
bool doesAliceWin(string s) {
11-
12-
}
12+
bool doesAliceWin(const string &s) {
13+
return std::any_of(s.begin(), s.end(), [](const char c) -> bool {
14+
return VOWELS.find(c) != VOWELS.npos;
15+
});
16+
}
1317
};
1418

1519
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);
20+
vector<string> inputArray;
21+
size_t pos = input_json_values.find('\n');
22+
while (pos != string::npos) {
23+
inputArray.push_back(input_json_values.substr(0, pos));
24+
input_json_values = input_json_values.substr(pos + 1);
25+
pos = input_json_values.find('\n');
26+
}
27+
inputArray.push_back(input_json_values);
2428

25-
Solution solution;
26-
string s = json::parse(inputArray.at(0));
27-
return solution.doesAliceWin(s);
29+
Solution solution;
30+
string s = json::parse(inputArray.at(0));
31+
return solution.doesAliceWin(s);
2832
}

problems/problems_3227/Solution.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66

77

88
public class Solution extends BaseSolution {
9+
private static final String VOWELS = "aeiou";
910
public boolean doesAliceWin(String s) {
10-
11+
for (int i = 0; i < s.length(); ++i) {
12+
if (VOWELS.indexOf(s.charAt(i)) >= 0) {
13+
return true;
14+
}
15+
}
16+
return false;
1117
}
1218

1319
@Override

problems/problems_3227/solution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func doesAliceWin(s string) bool {
10-
10+
return strings.ContainsAny(s, "aeiou")
1111
}
1212

1313
func Solve(inputJsonValues string) any {

problems/problems_3227/solution.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ def solve(self, test_input=None):
77
return self.doesAliceWin(test_input)
88

99
def doesAliceWin(self, s: str) -> bool:
10-
pass
11-
10+
return any(c in "aeiou" for c in s)

0 commit comments

Comments
 (0)