Skip to content

Commit a1e1046

Browse files
authored
Merge pull request #76 from SilentSliver/master
Merge from master
2 parents 89675e0 + 4f4e305 commit a1e1046

25 files changed

+497
-71
lines changed

CHANGELOG.md

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
# CHANGELOG
22

3+
## v10.1.2 (2025-06-17)
4+
5+
### Fix
6+
7+
* fix: maven problem folder and bazel plans
8+
9+
should be PROBLEM_FOLDER. bazel should handle empty plans ([`a28bd3a`](https://github.com/QuBenhao/LeetCode/commit/a28bd3a91edd062b5a8da421e6dc1a6d50a60d84))
10+
11+
* fix: handle old python
12+
13+
submit old python code with test_input not having =None ([`2d593ea`](https://github.com/QuBenhao/LeetCode/commit/2d593ea0cc25abdbcbcf9076daf2545283db48fd))
14+
15+
* fix: use path.join for file paths in tests
16+
17+
ts path remove '/' ([`9ceb2ea`](https://github.com/QuBenhao/LeetCode/commit/9ceb2ea3b152715da42246ae09becf3ac98d054e))
18+
19+
### Test
20+
21+
* test: 813 solution
22+
23+
py ([`dffb5c8`](https://github.com/QuBenhao/LeetCode/commit/dffb5c8cf67d38afd67bcf098e102198a0f7fec7))
24+
25+
* test: 808 solution
26+
27+
py, c++, java, go ([`ad89ad7`](https://github.com/QuBenhao/LeetCode/commit/ad89ad7d0a4db892f0b4654c58c9f1fd6cab1139))
28+
29+
* test: add 808, 813
30+
31+
add py, c++, go, java problems ([`d85887a`](https://github.com/QuBenhao/LeetCode/commit/d85887a153259e333279d3ea51df803845590afb))
32+
33+
* test: 3405 solution
34+
35+
py, c++, go, java ([`15f6fe5`](https://github.com/QuBenhao/LeetCode/commit/15f6fe5d69a20bb8ced0c28068c8e6df7f9724bf))
36+
37+
* test: [20250617] Add (3405) ([`1c381e6`](https://github.com/QuBenhao/LeetCode/commit/1c381e61bb0180b7c31bfc6568d13e8273bfd8e1))
38+
339
## v10.1.1 (2025-06-16)
440

541
### Fix
@@ -192,34 +228,6 @@ py, c++, go ([`b647870`](https://github.com/QuBenhao/LeetCode/commit/b64787041b5
192228

193229
## v10.0.2 (2025-06-12)
194230

195-
### Fix
196-
197-
* fix: bazel cache issue & daily
198-
199-
update daily problem handling and test generation in BUILD and solutions ([`c506b4b`](https://github.com/QuBenhao/LeetCode/commit/c506b4bd60d94ebaf970d1b6d2a54e1ba9cb4ca6))
200-
201-
* fix: update page size limit in input handling
202-
203-
limit ([`28c5869`](https://github.com/QuBenhao/LeetCode/commit/28c58698d48c2e96ad5cbd738ecea406670e5359))
204-
205-
### Test
206-
207-
* test: 2767 solution
208-
209-
py, c++, go, java ([`1be5b70`](https://github.com/QuBenhao/LeetCode/commit/1be5b70ae3ef91da1c6474bfe7b4424931d0021f))
210-
211-
* test: 3423 solution
212-
213-
py, c++, go, java ([`241565b`](https://github.com/QuBenhao/LeetCode/commit/241565b15a08a053fe142256e3fefe4e2f06c765))
214-
215-
* test: [20250612] Add (3423) ([`bda75a0`](https://github.com/QuBenhao/LeetCode/commit/bda75a0003ce232d65e50ebde4a0dd591b8dd4d4))
216-
217-
* test: 792 solution
218-
219-
py ([`5a6f52f`](https://github.com/QuBenhao/LeetCode/commit/5a6f52f536a6d0f85166b6b81cedad7880b0b26b))
220-
221-
## v10.0.1 (2025-06-11)
222-
223231
### Breaking
224232

225233
* feat!: 157 daily problem design (#158)
@@ -1382,6 +1390,14 @@ Generate linkedList from int array or the opposite, as well as basic test for li
13821390

13831391
### Fix
13841392

1393+
* fix: bazel cache issue & daily
1394+
1395+
update daily problem handling and test generation in BUILD and solutions ([`c506b4b`](https://github.com/QuBenhao/LeetCode/commit/c506b4bd60d94ebaf970d1b6d2a54e1ba9cb4ca6))
1396+
1397+
* fix: update page size limit in input handling
1398+
1399+
limit ([`28c5869`](https://github.com/QuBenhao/LeetCode/commit/28c58698d48c2e96ad5cbd738ecea406670e5359))
1400+
13851401
* fix: get_solution_code
13861402

13871403
now py, c++, go & java should get problem id from daily json ([`c38ea7f`](https://github.com/QuBenhao/LeetCode/commit/c38ea7f13b42cde86a4d70854f29eaa171f1484b))
@@ -2942,6 +2958,20 @@ go.sum uploaded ([`064618d`](https://github.com/QuBenhao/LeetCode/commit/064618d
29422958

29432959
### Test
29442960

2961+
* test: 2767 solution
2962+
2963+
py, c++, go, java ([`1be5b70`](https://github.com/QuBenhao/LeetCode/commit/1be5b70ae3ef91da1c6474bfe7b4424931d0021f))
2964+
2965+
* test: 3423 solution
2966+
2967+
py, c++, go, java ([`241565b`](https://github.com/QuBenhao/LeetCode/commit/241565b15a08a053fe142256e3fefe4e2f06c765))
2968+
2969+
* test: [20250612] Add (3423) ([`bda75a0`](https://github.com/QuBenhao/LeetCode/commit/bda75a0003ce232d65e50ebde4a0dd591b8dd4d4))
2970+
2971+
* test: 792 solution
2972+
2973+
py ([`5a6f52f`](https://github.com/QuBenhao/LeetCode/commit/5a6f52f536a6d0f85166b6b81cedad7880b0b26b))
2974+
29452975
* test: 792 solution
29462976

29472977
c++, go, java ([`c394bc8`](https://github.com/QuBenhao/LeetCode/commit/c394bc80d5bcee0d7db06133b49aef32761abbab))

cpp/models/ListNode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ListNode *IntArrayToListNodeCycle(std::vector<int> &arr, int pos) {
3232
for (size_t i = 0; i < arr.size(); ++i) {
3333
p->next = new ListNode(arr[i]);
3434
p = p->next;
35-
if (i == pos) {
35+
if (static_cast<int>(i) == pos) {
3636
cycle = p;
3737
}
3838
}

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "3405",
2+
"daily": "813",
33
"plans": ["3582", "problems", "3583", "problems", "3584", "problems", "3585", "problems"]
44
}

extensions.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ def _impl(rctx):
88
fail("Failed to get daily problem path: %s" % result.stderr)
99
s = result.stdout.strip()
1010
splits = s.splitlines()
11-
if len(splits) != 3:
12-
fail("Expected three lines in output, got: %s" % s)
11+
if len(splits) != 2 and len(splits) != 3:
12+
fail("Expected two or three lines in output, got: %s" % s)
1313
folder = splits[0]
1414
rctx.path(Label("//:daily-" + folder + ".json"))
1515
daily_problem = splits[1]
16-
plans = splits[2]
16+
plans = splits[2] if len(splits) == 3 else ""
1717
rctx.file("BUILD", "exports_files([\"daily.bzl\"])\nvisibility = [\"//visibility:public\"]\n")
1818
rctx.file("daily.bzl", """
1919
FOLDER = "%s"

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

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

pom.xml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@
100100
def baseDir = "problems"
101101
if (envFile.exists()) {
102102
envFile.eachLine { line ->
103-
if (line.startsWith("PROBLEMS_FOLDER=")) {
103+
if (line.startsWith("PROBLEM_FOLDER=")) {
104104
baseDir = line.split("=")[1].trim()
105+
baseDir = baseDir.replaceAll('"', '')
105106
}
106107
}
108+
println "Using base directory from .env file: ${baseDir}"
109+
} else {
110+
println "Error: ${envFile.absolutePath} not found, using default base directory: ${baseDir}"
107111
}
108112
109113
// 2. 读取config.json
@@ -116,13 +120,18 @@
116120
// 3. 构建源目录列表
117121
def sources = [] as Set
118122
sources.add(Paths.get(project.basedir.toString(), baseDir, "${baseDir}_${config.daily}").toFile().absolutePath)
119-
for (int i = 0; i < config.plans.size(); i += 2) {
120-
def problem = config.plans[i]
121-
def folder = config.plans[i + 1]
122-
sources.add(Paths.get(project.basedir.toString(), folder, "${folder}_${problem}").toFile().absolutePath)
123+
// config.plans might be null or empty, handle it gracefully
124+
if (config.plans == null || config.plans.isEmpty()) {
125+
println "Warning: No plans found in config, using only daily source."
126+
} else {
127+
for (int i = 0; i < config.plans.size(); i += 2) {
128+
def problem = config.plans[i]
129+
def folder = config.plans[i + 1]
130+
sources.add(Paths.get(project.basedir.toString(), folder, "${folder}_${problem}").toFile().absolutePath)
131+
}
123132
}
124133
125-
println "==> 添加动态源目录:"
134+
println "==> Add dynamic source roots:"
126135
sources.each { println " - $it" }
127136
128137
// 4. 设置Maven属性

problems/problems_808/Solution.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
double soupServings(int n) {
11+
if (n == 0) {
12+
return 0.5;
13+
}
14+
n = (n + 24) / 25; // Round up to the nearest integer
15+
if (n >= 178) {
16+
return 1.0; // If n is large enough, return 1.0
17+
}
18+
vector<vector<double>> dp(n+1, vector<double>(n+1));
19+
dp[0][0] = 0.5; // Base case: both soups are empty
20+
for (int j = 1; j <= n; ++j) {
21+
dp[0][j] = 1.0; // If soup A is empty, all of soup B is consumed
22+
}
23+
for (int i = 1; i <= n; ++i) {
24+
for (int j = 1; j <= n; ++j) {
25+
dp[i][j] = 0.25 * (dp[max(0, i - 4)][j] + dp[max(0, i - 3)][max(0, j - 1)] +
26+
dp[max(0, i - 2)][max(0, j - 2)] + dp[max(0, i - 1)][max(0, j - 3)]);
27+
}
28+
}
29+
return dp[n][n];
30+
}
31+
};
32+
33+
json leetcode::qubh::Solve(string input_json_values) {
34+
vector<string> inputArray;
35+
size_t pos = input_json_values.find('\n');
36+
while (pos != string::npos) {
37+
inputArray.push_back(input_json_values.substr(0, pos));
38+
input_json_values = input_json_values.substr(pos + 1);
39+
pos = input_json_values.find('\n');
40+
}
41+
inputArray.push_back(input_json_values);
42+
43+
Solution solution;
44+
int n = json::parse(inputArray.at(0));
45+
return solution.soupServings(n);
46+
}

problems/problems_808/Solution.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package problems.problems_808;
2+
3+
import java.util.Arrays;
4+
5+
import com.alibaba.fastjson.JSON;
6+
7+
import qubhjava.BaseSolution;
8+
9+
10+
public class Solution extends BaseSolution {
11+
public double soupServings(int n) {
12+
if (n == 0) {
13+
return 0.5;
14+
}
15+
n = (n + 24) / 25; // Convert to servings of 25 ml
16+
if (n >= 178) {
17+
return 1.0; // If n is large enough, return 1.0
18+
}
19+
double[][] dp = new double[n + 1][n + 1];
20+
Arrays.fill(dp[0], 1.0); // If soup A is empty, soup B will finish
21+
dp[0][0] = 0.5; // Base case: both soups empty
22+
for (int i = 1; i <= n; ++i) {
23+
for (int j = 1; j <= n; ++j) {
24+
dp[i][j] = 0.25 * (dp[Math.max(i - 4, 0)][j] + dp[Math.max(i - 3, 0)][Math.max(j - 1, 0)] +
25+
dp[Math.max(i - 2, 0)][Math.max(j - 2, 0)] + dp[Math.max(i-1, 0)][Math.max(j - 3, 0)]);
26+
}
27+
}
28+
return dp[n][n];
29+
}
30+
31+
@Override
32+
public Object solve(String[] inputJsonValues) {
33+
int n = Integer.parseInt(inputJsonValues[0]);
34+
return JSON.toJSON(soupServings(n));
35+
}
36+
}

problems/problems_808/problem.md

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
# 808. Soup Servings [Rating: 2396.63]
22

3-
There are two types of soup: type A and type B. Initially we have `N` ml of each type of soup. There are four kinds of operations:
3+
<p>There are two types of soup: <strong>type A</strong> and <strong>type B</strong>. Initially, we have <code>n</code> ml of each type of soup. There are four kinds of operations:</p>
44

5-
1. Serve 100 ml of soup A and 0 ml of soup B
6-
2. Serve 75 ml of soup A and 25 ml of soup B
7-
3. Serve 50 ml of soup A and 50 ml of soup B
8-
4. Serve 25 ml of soup A and 75 ml of soup B
5+
<ol>
6+
<li>Serve <code>100</code> ml of <strong>soup A</strong> and <code>0</code> ml of <strong>soup B</strong>,</li>
7+
<li>Serve <code>75</code> ml of <strong>soup A</strong> and <code>25</code> ml of <strong>soup B</strong>,</li>
8+
<li>Serve <code>50</code> ml of <strong>soup A</strong> and <code>50</code> ml of <strong>soup B</strong>, and</li>
9+
<li>Serve <code>25</code> ml of <strong>soup A</strong> and <code>75</code> ml of <strong>soup B</strong>.</li>
10+
</ol>
911

10-
When we serve some soup, we give it to someone and we no longer have it. Each turn, we will choose from the four operations with equal probability 0.25. If the remaining volume of soup is not enough to complete the operation, we will serve as much as we can. We stop once we no longer have some quantity of both types of soup.
12+
<p>When we serve some soup, we give it to someone, and we no longer have it. Each turn, we will choose from the four operations with an equal probability <code>0.25</code>. If the remaining volume of soup is not enough to complete the operation, we will serve as much as possible. We stop once we no longer have some quantity of both types of soup.</p>
1113

12-
Note that we do not have the operation where all 100 ml's of soup B are used first.
14+
<p><strong>Note</strong> that we do not have an operation where all <code>100</code> ml&#39;s of <strong>soup B</strong> are used first.</p>
1315

14-
Return the probability that soup A will be empty first, plus half the probability that A and B become empty at the same time.
16+
<p>Return <em>the probability that <strong>soup A</strong> will be empty first, plus half the probability that <strong>A</strong> and <strong>B</strong> become empty at the same time</em>. Answers within <code>10<sup>-5</sup></code> of the actual answer will be accepted.</p>
1517

16-
18+
<p>&nbsp;</p>
19+
<p><strong class="example">Example 1:</strong></p>
1720

18-
```
19-
Example:
20-
Input: N = 50
21-
Output: 0.625
22-
Explanation:
23-
If we choose the first two operations, A will become empty first. For the third operation, A and B will become empty at the same time. For the fourth operation, B will become empty first. So the total probability of A becoming empty first plus half the probability that A and B become empty at the same time, is 0.25 * (1 + 1 + 0.5 + 0) = 0.625.
24-
```
21+
<pre>
22+
<strong>Input:</strong> n = 50
23+
<strong>Output:</strong> 0.62500
24+
<strong>Explanation:</strong> If we choose the first two operations, A will become empty first.
25+
For the third operation, A and B will become empty at the same time.
26+
For the fourth operation, B will become empty first.
27+
So the total probability of A becoming empty first plus half the probability that A and B become empty at the same time, is 0.25 * (1 + 1 + 0.5 + 0) = 0.625.
28+
</pre>
2529

26-
**Notes:**
30+
<p><strong class="example">Example 2:</strong></p>
2731

28-
- `0 <= N <= 10^9`.
29-
- Answers within `10^-6` of the true value will be accepted as correct.
32+
<pre>
33+
<strong>Input:</strong> n = 100
34+
<strong>Output:</strong> 0.71875
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>0 &lt;= n &lt;= 10<sup>9</sup></code></li>
42+
</ul>

problems/problems_808/problem_zh.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# 808. 分汤 [难度分: 2396.63]
2+
3+
<p>有&nbsp;<strong>A&nbsp;&nbsp;B 两种类型&nbsp;</strong>的汤。一开始每种类型的汤有&nbsp;<code>n</code>&nbsp;毫升。有四种分配操作:</p>
4+
5+
<ol>
6+
<li>提供 <code>100ml</code> 的 <strong>汤A</strong> 和 <code>0ml</code> 的 <strong>汤B</strong> 。</li>
7+
<li>提供 <code>75ml</code> 的 <strong>汤A</strong> 和 <code>25ml</code> 的 <strong>汤B</strong> 。</li>
8+
<li>提供 <code>50ml</code> 的 <strong>汤A</strong> 和 <code>50ml</code> 的 <strong>汤B</strong> 。</li>
9+
<li>提供 <code>25ml</code> 的 <strong>汤A</strong> 和 <code>75ml</code> 的 <strong>汤B</strong> 。</li>
10+
</ol>
11+
12+
<p>当我们把汤分配给某人之后,汤就没有了。每个回合,我们将从四种概率同为 <code>0.25</code> 的操作中进行分配选择。如果汤的剩余量不足以完成某次操作,我们将尽可能分配。当两种类型的汤都分配完时,停止操作。</p>
13+
14+
<p><strong>注意&nbsp;</strong>不存在先分配 <code>100</code> ml <strong>汤B</strong> 的操作。</p>
15+
16+
<p>需要返回的值:&nbsp;<strong>汤A&nbsp;</strong>先分配完的概率 +&nbsp;&nbsp;<strong>汤A和汤B&nbsp;</strong>同时分配完的概率 / 2。返回值在正确答案&nbsp;<code>10<sup>-5</sup></code>&nbsp;的范围内将被认为是正确的。</p>
17+
18+
<p>&nbsp;</p>
19+
20+
<p><strong>示例 1:</strong></p>
21+
22+
<pre>
23+
<strong>输入:</strong> n = 50
24+
<strong>输出:</strong> 0.62500
25+
<strong>解释:</strong>如果我们选择前两个操作<strong>,</strong>A 首先将变为空。
26+
对于第三个操作,A 和 B 会同时变为空。
27+
对于第四个操作,B 首先将变为空。<strong>
28+
</strong>所以 A 变为空的总概率加上 A 和 B 同时变为空的概率的一半是 0.25 *(1 + 1 + 0.5 + 0)= 0.625。
29+
</pre>
30+
31+
<p><strong>示例 2:</strong></p>
32+
33+
<pre>
34+
<strong>输入:</strong> n = 100
35+
<strong>输出:</strong> 0.71875
36+
</pre>
37+
38+
<p>&nbsp;</p>
39+
40+
<p><strong>提示:</strong></p>
41+
42+
<ul>
43+
<li><code>0 &lt;= n &lt;= 10<sup>9</sup></code>​​​​​​​</li>
44+
</ul>

0 commit comments

Comments
 (0)