Skip to content

Merge from master #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 58 additions & 28 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# CHANGELOG

## v10.1.2 (2025-06-17)

### Fix

* fix: maven problem folder and bazel plans

should be PROBLEM_FOLDER. bazel should handle empty plans ([`a28bd3a`](https://github.com/QuBenhao/LeetCode/commit/a28bd3a91edd062b5a8da421e6dc1a6d50a60d84))

* fix: handle old python

submit old python code with test_input not having =None ([`2d593ea`](https://github.com/QuBenhao/LeetCode/commit/2d593ea0cc25abdbcbcf9076daf2545283db48fd))

* fix: use path.join for file paths in tests

ts path remove '/' ([`9ceb2ea`](https://github.com/QuBenhao/LeetCode/commit/9ceb2ea3b152715da42246ae09becf3ac98d054e))

### Test

* test: 813 solution

py ([`dffb5c8`](https://github.com/QuBenhao/LeetCode/commit/dffb5c8cf67d38afd67bcf098e102198a0f7fec7))

* test: 808 solution

py, c++, java, go ([`ad89ad7`](https://github.com/QuBenhao/LeetCode/commit/ad89ad7d0a4db892f0b4654c58c9f1fd6cab1139))

* test: add 808, 813

add py, c++, go, java problems ([`d85887a`](https://github.com/QuBenhao/LeetCode/commit/d85887a153259e333279d3ea51df803845590afb))

* test: 3405 solution

py, c++, go, java ([`15f6fe5`](https://github.com/QuBenhao/LeetCode/commit/15f6fe5d69a20bb8ced0c28068c8e6df7f9724bf))

* test: [20250617] Add (3405) ([`1c381e6`](https://github.com/QuBenhao/LeetCode/commit/1c381e61bb0180b7c31bfc6568d13e8273bfd8e1))

## v10.1.1 (2025-06-16)

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

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

### Fix

* fix: bazel cache issue & daily

update daily problem handling and test generation in BUILD and solutions ([`c506b4b`](https://github.com/QuBenhao/LeetCode/commit/c506b4bd60d94ebaf970d1b6d2a54e1ba9cb4ca6))

* fix: update page size limit in input handling

limit ([`28c5869`](https://github.com/QuBenhao/LeetCode/commit/28c58698d48c2e96ad5cbd738ecea406670e5359))

### Test

* test: 2767 solution

py, c++, go, java ([`1be5b70`](https://github.com/QuBenhao/LeetCode/commit/1be5b70ae3ef91da1c6474bfe7b4424931d0021f))

* test: 3423 solution

py, c++, go, java ([`241565b`](https://github.com/QuBenhao/LeetCode/commit/241565b15a08a053fe142256e3fefe4e2f06c765))

* test: [20250612] Add (3423) ([`bda75a0`](https://github.com/QuBenhao/LeetCode/commit/bda75a0003ce232d65e50ebde4a0dd591b8dd4d4))

* test: 792 solution

py ([`5a6f52f`](https://github.com/QuBenhao/LeetCode/commit/5a6f52f536a6d0f85166b6b81cedad7880b0b26b))

## v10.0.1 (2025-06-11)

### Breaking

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

### Fix

* fix: bazel cache issue & daily

update daily problem handling and test generation in BUILD and solutions ([`c506b4b`](https://github.com/QuBenhao/LeetCode/commit/c506b4bd60d94ebaf970d1b6d2a54e1ba9cb4ca6))

* fix: update page size limit in input handling

limit ([`28c5869`](https://github.com/QuBenhao/LeetCode/commit/28c58698d48c2e96ad5cbd738ecea406670e5359))

* fix: get_solution_code

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

### Test

* test: 2767 solution

py, c++, go, java ([`1be5b70`](https://github.com/QuBenhao/LeetCode/commit/1be5b70ae3ef91da1c6474bfe7b4424931d0021f))

* test: 3423 solution

py, c++, go, java ([`241565b`](https://github.com/QuBenhao/LeetCode/commit/241565b15a08a053fe142256e3fefe4e2f06c765))

* test: [20250612] Add (3423) ([`bda75a0`](https://github.com/QuBenhao/LeetCode/commit/bda75a0003ce232d65e50ebde4a0dd591b8dd4d4))

* test: 792 solution

py ([`5a6f52f`](https://github.com/QuBenhao/LeetCode/commit/5a6f52f536a6d0f85166b6b81cedad7880b0b26b))

* test: 792 solution

c++, go, java ([`c394bc8`](https://github.com/QuBenhao/LeetCode/commit/c394bc80d5bcee0d7db06133b49aef32761abbab))
Expand Down
2 changes: 1 addition & 1 deletion cpp/models/ListNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ListNode *IntArrayToListNodeCycle(std::vector<int> &arr, int pos) {
for (size_t i = 0; i < arr.size(); ++i) {
p->next = new ListNode(arr[i]);
p = p->next;
if (i == pos) {
if (static_cast<int>(i) == pos) {
cycle = p;
}
}
Expand Down
2 changes: 1 addition & 1 deletion daily-problems.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"daily": "3405",
"daily": "813",
"plans": ["3582", "problems", "3583", "problems", "3584", "problems", "3585", "problems"]
}
6 changes: 3 additions & 3 deletions extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def _impl(rctx):
fail("Failed to get daily problem path: %s" % result.stderr)
s = result.stdout.strip()
splits = s.splitlines()
if len(splits) != 3:
fail("Expected three lines in output, got: %s" % s)
if len(splits) != 2 and len(splits) != 3:
fail("Expected two or three lines in output, got: %s" % s)
folder = splits[0]
rctx.path(Label("//:daily-" + folder + ".json"))
daily_problem = splits[1]
plans = splits[2]
plans = splits[2] if len(splits) == 3 else ""
rctx.file("BUILD", "exports_files([\"daily.bzl\"])\nvisibility = [\"//visibility:public\"]\n")
rctx.file("daily.bzl", """
FOLDER = "%s"
Expand Down
4 changes: 2 additions & 2 deletions golang/solution_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package golang

import (
problem "leetCode/problems/problems_3405"
problem "leetCode/problems/problems_813"
"testing"
)

func TestSolution(t *testing.T) {
TestEach(t, "3405", "problems", problem.Solve)
TestEach(t, "813", "problems", problem.Solve)
}
21 changes: 15 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@
def baseDir = "problems"
if (envFile.exists()) {
envFile.eachLine { line ->
if (line.startsWith("PROBLEMS_FOLDER=")) {
if (line.startsWith("PROBLEM_FOLDER=")) {
baseDir = line.split("=")[1].trim()
baseDir = baseDir.replaceAll('"', '')
}
}
println "Using base directory from .env file: ${baseDir}"
} else {
println "Error: ${envFile.absolutePath} not found, using default base directory: ${baseDir}"
}

// 2. 读取config.json
Expand All @@ -116,13 +120,18 @@
// 3. 构建源目录列表
def sources = [] as Set
sources.add(Paths.get(project.basedir.toString(), baseDir, "${baseDir}_${config.daily}").toFile().absolutePath)
for (int i = 0; i < config.plans.size(); i += 2) {
def problem = config.plans[i]
def folder = config.plans[i + 1]
sources.add(Paths.get(project.basedir.toString(), folder, "${folder}_${problem}").toFile().absolutePath)
// config.plans might be null or empty, handle it gracefully
if (config.plans == null || config.plans.isEmpty()) {
println "Warning: No plans found in config, using only daily source."
} else {
for (int i = 0; i < config.plans.size(); i += 2) {
def problem = config.plans[i]
def folder = config.plans[i + 1]
sources.add(Paths.get(project.basedir.toString(), folder, "${folder}_${problem}").toFile().absolutePath)
}
}

println "==> 添加动态源目录:"
println "==> Add dynamic source roots:"
sources.each { println " - $it" }

// 4. 设置Maven属性
Expand Down
46 changes: 46 additions & 0 deletions problems/problems_808/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//go:build ignore
#include "cpp/common/Solution.h"


using namespace std;
using json = nlohmann::json;

class Solution {
public:
double soupServings(int n) {
if (n == 0) {
return 0.5;
}
n = (n + 24) / 25; // Round up to the nearest integer
if (n >= 178) {
return 1.0; // If n is large enough, return 1.0
}
vector<vector<double>> dp(n+1, vector<double>(n+1));
dp[0][0] = 0.5; // Base case: both soups are empty
for (int j = 1; j <= n; ++j) {
dp[0][j] = 1.0; // If soup A is empty, all of soup B is consumed
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
dp[i][j] = 0.25 * (dp[max(0, i - 4)][j] + dp[max(0, i - 3)][max(0, j - 1)] +
dp[max(0, i - 2)][max(0, j - 2)] + dp[max(0, i - 1)][max(0, j - 3)]);
}
}
return dp[n][n];
}
};

json leetcode::qubh::Solve(string input_json_values) {
vector<string> inputArray;
size_t pos = input_json_values.find('\n');
while (pos != string::npos) {
inputArray.push_back(input_json_values.substr(0, pos));
input_json_values = input_json_values.substr(pos + 1);
pos = input_json_values.find('\n');
}
inputArray.push_back(input_json_values);

Solution solution;
int n = json::parse(inputArray.at(0));
return solution.soupServings(n);
}
36 changes: 36 additions & 0 deletions problems/problems_808/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package problems.problems_808;

import java.util.Arrays;

import com.alibaba.fastjson.JSON;

import qubhjava.BaseSolution;


public class Solution extends BaseSolution {
public double soupServings(int n) {
if (n == 0) {
return 0.5;
}
n = (n + 24) / 25; // Convert to servings of 25 ml
if (n >= 178) {
return 1.0; // If n is large enough, return 1.0
}
double[][] dp = new double[n + 1][n + 1];
Arrays.fill(dp[0], 1.0); // If soup A is empty, soup B will finish
dp[0][0] = 0.5; // Base case: both soups empty
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
dp[i][j] = 0.25 * (dp[Math.max(i - 4, 0)][j] + dp[Math.max(i - 3, 0)][Math.max(j - 1, 0)] +
dp[Math.max(i - 2, 0)][Math.max(j - 2, 0)] + dp[Math.max(i-1, 0)][Math.max(j - 3, 0)]);
}
}
return dp[n][n];
}

@Override
public Object solve(String[] inputJsonValues) {
int n = Integer.parseInt(inputJsonValues[0]);
return JSON.toJSON(soupServings(n));
}
}
51 changes: 32 additions & 19 deletions problems/problems_808/problem.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
# 808. Soup Servings [Rating: 2396.63]

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:
<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>

1. Serve 100 ml of soup A and 0 ml of soup B
2. Serve 75 ml of soup A and 25 ml of soup B
3. Serve 50 ml of soup A and 50 ml of soup B
4. Serve 25 ml of soup A and 75 ml of soup B
<ol>
<li>Serve <code>100</code> ml of <strong>soup A</strong> and <code>0</code> ml of <strong>soup B</strong>,</li>
<li>Serve <code>75</code> ml of <strong>soup A</strong> and <code>25</code> ml of <strong>soup B</strong>,</li>
<li>Serve <code>50</code> ml of <strong>soup A</strong> and <code>50</code> ml of <strong>soup B</strong>, and</li>
<li>Serve <code>25</code> ml of <strong>soup A</strong> and <code>75</code> ml of <strong>soup B</strong>.</li>
</ol>

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.
<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>

Note that we do not have the operation where all 100 ml's of soup B are used first.
<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>

Return the probability that soup A will be empty first, plus half the probability that A and B become empty at the same time.
<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>


<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

```
Example:
Input: N = 50
Output: 0.625
Explanation:
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.
```
<pre>
<strong>Input:</strong> n = 50
<strong>Output:</strong> 0.62500
<strong>Explanation:</strong> 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.
</pre>

**Notes:**
<p><strong class="example">Example 2:</strong></p>

- `0 <= N <= 10^9`.
- Answers within `10^-6` of the true value will be accepted as correct.
<pre>
<strong>Input:</strong> n = 100
<strong>Output:</strong> 0.71875
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>0 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>
44 changes: 44 additions & 0 deletions problems/problems_808/problem_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 808. 分汤 [难度分: 2396.63]

<p>有&nbsp;<strong>A&nbsp;和&nbsp;B 两种类型&nbsp;</strong>的汤。一开始每种类型的汤有&nbsp;<code>n</code>&nbsp;毫升。有四种分配操作:</p>

<ol>
<li>提供 <code>100ml</code> 的 <strong>汤A</strong> 和 <code>0ml</code> 的 <strong>汤B</strong> 。</li>
<li>提供 <code>75ml</code> 的 <strong>汤A</strong> 和 <code>25ml</code> 的 <strong>汤B</strong> 。</li>
<li>提供 <code>50ml</code> 的 <strong>汤A</strong> 和 <code>50ml</code> 的 <strong>汤B</strong> 。</li>
<li>提供 <code>25ml</code> 的 <strong>汤A</strong> 和 <code>75ml</code> 的 <strong>汤B</strong> 。</li>
</ol>

<p>当我们把汤分配给某人之后,汤就没有了。每个回合,我们将从四种概率同为 <code>0.25</code> 的操作中进行分配选择。如果汤的剩余量不足以完成某次操作,我们将尽可能分配。当两种类型的汤都分配完时,停止操作。</p>

<p><strong>注意&nbsp;</strong>不存在先分配 <code>100</code> ml <strong>汤B</strong> 的操作。</p>

<p>需要返回的值:&nbsp;<strong>汤A&nbsp;</strong>先分配完的概率 +&nbsp;&nbsp;<strong>汤A和汤B&nbsp;</strong>同时分配完的概率 / 2。返回值在正确答案&nbsp;<code>10<sup>-5</sup></code>&nbsp;的范围内将被认为是正确的。</p>

<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>

<pre>
<strong>输入:</strong> n = 50
<strong>输出:</strong> 0.62500
<strong>解释:</strong>如果我们选择前两个操作<strong>,</strong>A 首先将变为空。
对于第三个操作,A 和 B 会同时变为空。
对于第四个操作,B 首先将变为空。<strong>
</strong>所以 A 变为空的总概率加上 A 和 B 同时变为空的概率的一半是 0.25 *(1 + 1 + 0.5 + 0)= 0.625。
</pre>

<p><strong>示例 2:</strong></p>

<pre>
<strong>输入:</strong> n = 100
<strong>输出:</strong> 0.71875
</pre>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>0 &lt;= n &lt;= 10<sup>9</sup></code>​​​​​​​</li>
</ul>
Loading