Skip to content

Commit ea977e4

Browse files
committed
test: [20241209] Add daily LeetCode problem
1 parent 53541d2 commit ea977e4

File tree

16 files changed

+200
-38
lines changed

16 files changed

+200
-38
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ members = [
282282
"problems/problems_999",
283283
"problems/problems_688",
284284
"problems/problems_782",
285+
"problems/problems_1812",
285286
]
286287

287288
[package]
@@ -586,3 +587,4 @@ solution_3001 = { path = "problems/problems_3001", features = ["solution_3001"]
586587
solution_999 = { path = "problems/problems_999", features = ["solution_999"] }
587588
solution_688 = { path = "problems/problems_688", features = ["solution_688"] }
588589
solution_782 = { path = "problems/problems_782", features = ["solution_782"] }
590+
solution_1812 = { path = "problems/problems_1812", features = ["solution_1812"] }

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ git_repository(
3737
new_local_repository(
3838
name = "problems",
3939
build_file = "//cpp:solution.BUILD",
40-
path = "problems/problems_782/",
40+
path = "problems/problems_1812/",
4141
)
4242

4343
new_local_repository(

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_782"
4+
problem "leetCode/problems/problems_1812"
55
"testing"
66
)
77

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

problems/problems_1812/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_1812"
3+
version = "0.1.0"
4+
edition = "2021"
5+
rust-version = "1.79.0"
6+
authors = ["benhao"]
7+
description = "LeetCode Solution 1812 in Rust"
8+
readme = "../../README.md"
9+
10+
[features]
11+
solution_1812 = []
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_1812"
21+
path = "solution.rs"

problems/problems_1812/Solution.cpp

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 squareIsWhite(string coordinates) {
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 coordinates = json::parse(inputArray.at(0));
27+
return solution.squareIsWhite(coordinates);
28+
}

problems/problems_1812/Solution.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package problems.problems_1812;
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 squareIsWhite(String coordinates) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
String coordinates = jsonStringToString(inputJsonValues[0]);
16+
return JSON.toJSON(squareIsWhite(coordinates));
17+
}
18+
}

problems/problems_1812/problem.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
# 1812. Determine Color of a Chessboard Square [Rating: 1328.51]
22

3-
You are given `coordinates`, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.
3+
<p>You are given <code>coordinates</code>, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference.</p>
44

5-
![img](https://assets.leetcode.com/uploads/2021/02/19/screenshot-2021-02-20-at-22159-pm.png)
5+
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/02/19/screenshot-2021-02-20-at-22159-pm.png" style="width: 400px; height: 396px;" /></p>
66

7-
Return `true` *if the square is white, and* `false` *if the square is black*.
7+
<p>Return <code>true</code><em> if the square is white, and </em><code>false</code><em> if the square is black</em>.</p>
88

9-
The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.
9+
<p>The coordinate will always represent a valid chessboard square. The coordinate will always have the letter first, and the number second.</p>
1010

11-
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
1213

13-
**Example 1:**
14+
<pre>
15+
<strong>Input:</strong> coordinates = &quot;a1&quot;
16+
<strong>Output:</strong> false
17+
<strong>Explanation:</strong> From the chessboard above, the square with coordinates &quot;a1&quot; is black, so return false.
18+
</pre>
1419

15-
```
16-
Input: coordinates = "a1"
17-
Output: false
18-
Explanation: From the chessboard above, the square with coordinates "a1" is black, so return false.
19-
```
20+
<p><strong class="example">Example 2:</strong></p>
2021

21-
**Example 2:**
22+
<pre>
23+
<strong>Input:</strong> coordinates = &quot;h3&quot;
24+
<strong>Output:</strong> true
25+
<strong>Explanation:</strong> From the chessboard above, the square with coordinates &quot;h3&quot; is white, so return true.
26+
</pre>
2227

23-
```
24-
Input: coordinates = "h3"
25-
Output: true
26-
Explanation: From the chessboard above, the square with coordinates "h3" is white, so return true.
27-
```
28+
<p><strong class="example">Example 3:</strong></p>
2829

29-
**Example 3:**
30+
<pre>
31+
<strong>Input:</strong> coordinates = &quot;c7&quot;
32+
<strong>Output:</strong> false
33+
</pre>
3034

31-
```
32-
Input: coordinates = "c7"
33-
Output: false
34-
```
35+
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
3537

36-
37-
38-
**Constraints:**
39-
40-
- `coordinates.length == 2`
41-
- `'a' <= coordinates[0] <= 'h'`
42-
- `'1' <= coordinates[1] <= '8'`
38+
<ul>
39+
<li><code>coordinates.length == 2</code></li>
40+
<li><code>&#39;a&#39; &lt;= coordinates[0] &lt;= &#39;h&#39;</code></li>
41+
<li><code>&#39;1&#39; &lt;= coordinates[1] &lt;= &#39;8&#39;</code></li>
42+
</ul>

problems/problems_1812/problem_zh.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# 1812. 判断国际象棋棋盘中一个格子的颜色 [难度分: 1328.51]
2+
3+
<p>给你一个坐标 <code>coordinates</code> ,它是一个字符串,表示国际象棋棋盘中一个格子的坐标。下图是国际象棋棋盘示意图。</p>
4+
5+
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2021/04/03/chessboard.png" style="width: 400px; height: 396px;" /></p>
6+
7+
<p>如果所给格子的颜色是白色,请你返回 <code>true</code>,如果是黑色,请返回 <code>false</code> 。</p>
8+
9+
<p>给定坐标一定代表国际象棋棋盘上一个存在的格子。坐标第一个字符是字母,第二个字符是数字。</p>
10+
11+
<p> </p>
12+
13+
<p><strong>示例 1:</strong></p>
14+
15+
<pre>
16+
<b>输入:</b>coordinates = "a1"
17+
<b>输出:</b>false
18+
<b>解释:</b>如上图棋盘所示,"a1" 坐标的格子是黑色的,所以返回 false 。
19+
</pre>
20+
21+
<p><strong>示例 2:</strong></p>
22+
23+
<pre>
24+
<b>输入:</b>coordinates = "h3"
25+
<b>输出:</b>true
26+
<b>解释:</b>如上图棋盘所示,"h3" 坐标的格子是白色的,所以返回 true 。
27+
</pre>
28+
29+
<p><strong>示例 3:</strong></p>
30+
31+
<pre>
32+
<b>输入:</b>coordinates = "c7"
33+
<b>输出:</b>false
34+
</pre>
35+
36+
<p> </p>
37+
38+
<p><strong>提示:</strong></p>
39+
40+
<ul>
41+
<li><code>coordinates.length == 2</code></li>
42+
<li><code>'a' <= coordinates[0] <= 'h'</code></li>
43+
<li><code>'1' <= coordinates[1] <= '8'</code></li>
44+
</ul>

problems/problems_1812/solution.go

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

problems/problems_1812/solution.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use serde_json::{json, Value};
2+
3+
pub struct Solution;
4+
5+
impl Solution {
6+
pub fn square_is_white(coordinates: String) -> bool {
7+
8+
}
9+
}
10+
11+
#[cfg(feature = "solution_1812")]
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 coordinates: String = serde_json::from_str(&input_values[0]).expect("Failed to parse input");
15+
json!(Solution::square_is_white(coordinates))
16+
}

problems/problems_1812/solution.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function squareIsWhite(coordinates: string): boolean {
2+
3+
};
4+
5+
export function Solve(inputJsonElement: string): any {
6+
const inputValues: string[] = inputJsonElement.split("\n");
7+
const coordinates: string = JSON.parse(inputValues[0]);
8+
return squareIsWhite(coordinates);
9+
}

problems/problems_1812/testcase

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
["\"a1\"", "\"h3\"", "\"c7\""]
2+
[false, true, false]

python/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
logging.basicConfig(level=logging.INFO, format=constants.LOGGING_FORMAT, datefmt=constants.DATE_FORMAT)
1212

1313
# Question ID that wants to test, modify here as passing arguments
14-
QUESTION = "782"
14+
QUESTION = "1812"
1515
# QUESTION = "Interview/10_02"
1616
# QUESTION = "LCP/07"
1717
# QUESTION = "剑指Offer/52"

qubhjava/test/TestMain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.junit.jupiter.api.Timeout;
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
11-
import problems.problems_782.Solution;
11+
import problems.problems_1812.Solution;
1212
// import premiums.premiums_1056.Solution;
1313
import org.testng.util.Strings;
1414
import qubhjava.Testcase;
@@ -22,7 +22,7 @@
2222
public class TestMain {
2323

2424
private static final Logger log = LoggerFactory.getLogger(TestMain.class);
25-
private static final String PROBLEM_ID = "782";
25+
private static final String PROBLEM_ID = "1812";
2626

2727
private Testcase[] loadTestcases() throws IOException {
2828
String problemFolder = null;

rust/test_executor/tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const PROBLEM_FOLDER: &str = "problems";
2-
const PROBLEM_ID: &str = "782";
2+
const PROBLEM_ID: &str = "1812";
33

44
#[cfg(test)]
55
mod test {
6-
use solution_782 as solution;
6+
use solution_1812 as solution;
77
use test_executor::run_test::run_test;
88

99
use crate::{PROBLEM_FOLDER, PROBLEM_ID};

typescript/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var _ = require('lodash-contrib');
66
const vm = require('node:vm');
77
import {CompareResults} from "./common";
88

9-
const PROBLEM_ID: string = "782";
9+
const PROBLEM_ID: string = "1812";
1010

1111
describe("TestMain===" + PROBLEM_ID, () => {
1212
dotenv.config();

0 commit comments

Comments
 (0)