Skip to content

Commit 10dc3b1

Browse files
committed
test: 3683, 3684, 3685, 3686 solution
py, c++, go
1 parent 4b2f4f4 commit 10dc3b1

34 files changed

+969
-7
lines changed

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"daily": "966",
3-
"plans": ["3678", "problems", "3679", "problems", "3681", "problems"]
3+
"plans": ["3683", "problems", "3684", "problems", "3685", "problems", "3686", "problems"]
44
}

golang/problems_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package golang
22

33
import (
4-
problem3678 "leetCode/problems/problems_3678"
5-
problem3679 "leetCode/problems/problems_3679"
6-
problem3681 "leetCode/problems/problems_3681"
4+
problem3683 "leetCode/problems/problems_3683"
5+
problem3684 "leetCode/problems/problems_3684"
6+
problem3685 "leetCode/problems/problems_3685"
7+
problem3686 "leetCode/problems/problems_3686"
78
"testing"
89
)
910

1011
func TestSolutions(t *testing.T) {
11-
TestEach(t, "3678", "problems", problem3678.Solve)
12-
TestEach(t, "3679", "problems", problem3679.Solve)
13-
TestEach(t, "3681", "problems", problem3681.Solve)
12+
TestEach(t, "3683", "problems", problem3683.Solve)
13+
TestEach(t, "3684", "problems", problem3684.Solve)
14+
TestEach(t, "3685", "problems", problem3685.Solve)
15+
TestEach(t, "3686", "problems", problem3686.Solve)
1416
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//go:build ignore
2+
#include "cpp/common/Solution.h"
3+
4+
using namespace std;
5+
using json = nlohmann::json;
6+
7+
class Solution {
8+
public:
9+
int earliestTime(const vector<vector<int>> &tasks) {
10+
int mn = 201;
11+
for (const auto &task : tasks) {
12+
mn = min(mn, task[0] + task[1]);
13+
}
14+
return mn;
15+
}
16+
};
17+
18+
json leetcode::qubh::Solve(string input_json_values) {
19+
vector<string> inputArray;
20+
size_t pos = input_json_values.find('\n');
21+
while (pos != string::npos) {
22+
inputArray.push_back(input_json_values.substr(0, pos));
23+
input_json_values = input_json_values.substr(pos + 1);
24+
pos = input_json_values.find('\n');
25+
}
26+
inputArray.push_back(input_json_values);
27+
28+
Solution solution;
29+
vector<vector<int>> tasks = json::parse(inputArray.at(0));
30+
return solution.earliestTime(tasks);
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package problems.problems_3683;
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 int earliestTime(int[][] tasks) {
10+
int mn = 201;
11+
for (int[] task: tasks) {
12+
mn = Math.min(mn, task[0] + task[1]);
13+
}
14+
return mn;
15+
}
16+
17+
@Override
18+
public Object solve(String[] inputJsonValues) {
19+
int[][] tasks = jsonArrayToInt2DArray(inputJsonValues[0]);
20+
return JSON.toJSON(earliestTime(tasks));
21+
}
22+
}

problems/problems_3683/problem.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# 3683. Earliest Time to Finish One Task
2+
3+
<p>You are given a 2D integer array <code>tasks</code> where <code>tasks[i] = [s<sub>i</sub>, t<sub>i</sub>]</code>.</p>
4+
5+
<p>Each <code>[s<sub>i</sub>, t<sub>i</sub>]</code> in <code>tasks</code> represents a task with start time <code>s<sub>i</sub></code> that takes <code>t<sub>i</sub></code> units of time to finish.</p>
6+
7+
<p>Return the earliest time at which at least one task is finished.</p>
8+
9+
<p>&nbsp;</p>
10+
<p><strong class="example">Example 1:</strong></p>
11+
12+
<div class="example-block">
13+
<p><strong>Input:</strong> <span class="example-io">tasks = [[1,6],[2,3]]</span></p>
14+
15+
<p><strong>Output:</strong> <span class="example-io">5</span></p>
16+
17+
<p><strong>Explanation:</strong></p>
18+
19+
<p>The first task starts at time <code>t = 1</code> and finishes at time <code>1 + 6 = 7</code>. The second task finishes at time <code>2 + 3 = 5</code>. You can finish one task at time 5.</p>
20+
</div>
21+
22+
<p><strong class="example">Example 2:</strong></p>
23+
24+
<div class="example-block">
25+
<p><strong>Input:</strong> <span class="example-io">tasks = [[100,100],[100,100],[100,100]]</span></p>
26+
27+
<p><strong>Output:</strong> <span class="example-io">200</span></p>
28+
29+
<p><strong>Explanation:</strong></p>
30+
31+
<p>All three tasks finish at time <code>100 + 100 = 200</code>.</p>
32+
</div>
33+
34+
<p>&nbsp;</p>
35+
<p><strong>Constraints:</strong></p>
36+
37+
<ul>
38+
<li><code>1 &lt;= tasks.length &lt;= 100</code></li>
39+
<li><code>tasks[i] = [s<sub>i</sub>, t<sub>i</sub>]</code></li>
40+
<li><code>1 &lt;= s<sub>i</sub>, t<sub>i</sub> &lt;= 100</code></li>
41+
</ul>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# 3683. 完成一个任务的最早时间
2+
3+
<p>给你一个二维整数数组 <code>tasks</code>,其中 <code>tasks[i] = [s<sub>i</sub>, t<sub>i</sub>]</code>。</p>
4+
5+
<p>数组中的每个 <code>[s<sub>i</sub>, t<sub>i</sub>]</code> 表示一个任务,该任务的开始时间为 <code>s<sub>i</sub></code>,完成该任务需要 <code>t<sub>i</sub></code> 个时间单位。</p>
6+
7+
<p>返回至少完成一个任务的最早时间。</p>
8+
9+
<p>&nbsp;</p>
10+
11+
<p><strong class="example">示例 1:</strong></p>
12+
13+
<div class="example-block">
14+
<p><strong>输入:</strong> <span class="example-io">tasks = [[1,6],[2,3]]</span></p>
15+
16+
<p><strong>输出:</strong> <span class="example-io">5</span></p>
17+
18+
<p><strong>解释:</strong></p>
19+
20+
<p>第一个任务从时间 <code>t = 1</code> 开始,并在 <code>1 + 6 = 7</code> 时完成。第二个任务在时间 <code>t = 2</code> 开始,并在 <code>2 + 3 = 5</code> 时完成。因此,最早完成的任务在时间 5。</p>
21+
</div>
22+
23+
<p><strong class="example">示例 2:</strong></p>
24+
25+
<div class="example-block">
26+
<p><strong>输入:</strong> <span class="example-io">tasks = [[100,100],[100,100],[100,100]]</span></p>
27+
28+
<p><strong>输出:</strong> <span class="example-io">200</span></p>
29+
30+
<p><strong>解释:</strong></p>
31+
32+
<p>三个任务都在时间 <code>100 + 100 = 200</code> 时完成。</p>
33+
</div>
34+
35+
<p>&nbsp;</p>
36+
37+
<p><strong>提示:</strong></p>
38+
39+
<ul>
40+
<li><code>1 &lt;= tasks.length &lt;= 100</code></li>
41+
<li><code>tasks[i] = [s<sub>i</sub>, t<sub>i</sub>]</code></li>
42+
<li><code>1 &lt;= s<sub>i</sub>, t<sub>i</sub> &lt;= 100</code></li>
43+
</ul>

problems/problems_3683/solution.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package problem3683
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"strings"
7+
)
8+
9+
func earliestTime(tasks [][]int) (ans int) {
10+
ans = 201
11+
for _, task := range tasks {
12+
ans = min(ans, task[0]+task[1])
13+
}
14+
return
15+
}
16+
17+
func Solve(inputJsonValues string) any {
18+
inputValues := strings.Split(inputJsonValues, "\n")
19+
var tasks [][]int
20+
21+
if err := json.Unmarshal([]byte(inputValues[0]), &tasks); err != nil {
22+
log.Fatal(err)
23+
}
24+
25+
return earliestTime(tasks)
26+
}

problems/problems_3683/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.earliestTime(test_input)
8+
9+
def earliestTime(self, tasks: List[List[int]]) -> int:
10+
return min(s + t for s, t in tasks)
11+

problems/problems_3683/testcase

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
["[[1,6],[2,3]]", "[[100,100],[100,100],[100,100]]"]
2+
[5, 200]

problems/problems_3683/testcase.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from collections import namedtuple
2+
import testcase
3+
4+
case = namedtuple("Testcase", ["Input", "Output"])
5+
6+
7+
class Testcase(testcase.Testcase):
8+
def __init__(self):
9+
self.testcases = []
10+
self.testcases.append(case(Input=[[1, 6], [2, 3]], Output=5))
11+
self.testcases.append(case(Input=[[100, 100], [100, 100], [100, 100]], Output=200))
12+
13+
def get_testcases(self):
14+
return self.testcases

0 commit comments

Comments
 (0)