Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 685d080

Browse files
feat: add biweekly contest 129 (doocs#2675)
1 parent cd46406 commit 685d080

File tree

28 files changed

+1965
-2
lines changed

28 files changed

+1965
-2
lines changed

‎solution/2600-2699/2645.Minimum Additions to Make Valid String/README_EN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<pre>
1717
<strong>Input:</strong> word = &quot;b&quot;
1818
<strong>Output:</strong> 2
19-
<strong>Explanation:</strong> Insert the letter &quot;a&quot; right before &quot;b&quot;, and the letter &quot;c&quot; right next to &quot;a&quot; to obtain the valid string &quot;<strong>a</strong>b<strong>c</strong>&quot;.
19+
<strong>Explanation:</strong> Insert the letter &quot;a&quot; right before &quot;b&quot;, and the letter &quot;c&quot; right next to &quot;b&quot; to obtain the valid string &quot;<strong>a</strong>b<strong>c</strong>&quot;.
2020
</pre>
2121

2222
<p><strong class="example">Example 2:</strong></p>
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# [3126. Server Utilization Time](https://leetcode.cn/problems/server-utilization-time)
2+
3+
[English Version](/solution/3100-3199/3126.Server%20Utilization%20Time/README_EN.md)
4+
5+
<!-- tags: -->
6+
7+
## 题目描述
8+
9+
<!-- 这里写题目描述 -->
10+
11+
<p>Table: <code>Servers</code></p>
12+
13+
<pre>
14+
+----------------+----------+
15+
| Column Name | Type |
16+
+----------------+----------+
17+
| server_id | int |
18+
| status_time | datetime |
19+
| session_status | enum |
20+
+----------------+----------+
21+
(server_id, status_time, session_status) is the primary key (combination of columns with unique values) for this table.
22+
session_status is an ENUM (category) type of (&#39;start&#39;, &#39;stop&#39;).
23+
Each row of this table contains server_id, status_time, and session_status.
24+
</pre>
25+
26+
<p>Write a solution to find the <strong>total time</strong> when servers were <strong>running</strong>. The output should be in units of <strong>full days</strong>.</p>
27+
28+
<p>Return <em>the result table in <strong>any</strong></em><em>&nbsp;order.</em></p>
29+
30+
<p>The result format is in the following example.</p>
31+
32+
<p>&nbsp;</p>
33+
<p><strong class="example">Example:</strong></p>
34+
35+
<div class="example-block">
36+
<p><strong>Input:</strong></p>
37+
38+
<p>Servers table:</p>
39+
40+
<pre class="example-io">
41+
+-----------+---------------------+----------------+
42+
| server_id | status_time | session_status |
43+
+-----------+---------------------+----------------+
44+
| 3 | 2023年11月04日 16:29:47 | start |
45+
| 3 | 2023年11月05日 01:49:47 | stop |
46+
| 3 | 2023年11月25日 01:37:08 | start |
47+
| 3 | 2023年11月25日 03:50:08 | stop |
48+
| 1 | 2023年11月13日 03:05:31 | start |
49+
| 1 | 2023年11月13日 11:10:31 | stop |
50+
| 4 | 2023年11月29日 15:11:17 | start |
51+
| 4 | 2023年11月29日 15:42:17 | stop |
52+
| 4 | 2023年11月20日 00:31:44 | start |
53+
| 4 | 2023年11月20日 07:03:44 | stop |
54+
| 1 | 2023年11月20日 00:27:11 | start |
55+
| 1 | 2023年11月20日 01:41:11 | stop |
56+
| 3 | 2023年11月04日 23:16:48 | start |
57+
| 3 | 2023年11月05日 01:15:48 | stop |
58+
| 4 | 2023年11月30日 15:09:18 | start |
59+
| 4 | 2023年11月30日 20:48:18 | stop |
60+
| 4 | 2023年11月25日 21:09:06 | start |
61+
| 4 | 2023年11月26日 04:58:06 | stop |
62+
| 5 | 2023年11月16日 19:42:22 | start |
63+
| 5 | 2023年11月16日 21:08:22 | stop |
64+
+-----------+---------------------+----------------+
65+
</pre>
66+
67+
<p><strong>Output:</strong></p>
68+
69+
<pre class="example-io">
70+
+-------------------+
71+
| total_uptime_days |
72+
+-------------------+
73+
| 1 |
74+
+-------------------+
75+
</pre>
76+
77+
<p><strong>Explanation:</strong></p>
78+
79+
<ul>
80+
<li>For server ID 3:
81+
<ul>
82+
<li>From 2023年11月04日 16:29:47 to 2023年11月05日 01:49:47: ~9.3 hours</li>
83+
<li>From 2023年11月25日 01:37:08 to 2023年11月25日 03:50:08: ~2.2 hours</li>
84+
<li>From 2023年11月04日 23:16:48 to 2023年11月05日 01:15:48: ~1.98 hours</li>
85+
</ul>
86+
Total for server 3: ~13.48 hours</li>
87+
<li>For server ID 1:
88+
<ul>
89+
<li>From 2023年11月13日 03:05:31 to 2023年11月13日 11:10:31: ~8 hours</li>
90+
<li>From 2023年11月20日 00:27:11 to 2023年11月20日 01:41:11: ~1.23 hours</li>
91+
</ul>
92+
Total for server 1: ~9.23 hours</li>
93+
<li>For server ID 4:
94+
<ul>
95+
<li>From 2023年11月29日 15:11:17 to 2023年11月29日 15:42:17: ~0.52 hours</li>
96+
<li>From 2023年11月20日 00:31:44 to 2023年11月20日 07:03:44: ~6.53 hours</li>
97+
<li>From 2023年11月30日 15:09:18 to 2023年11月30日 20:48:18: ~5.65 hours</li>
98+
<li>From 2023年11月25日 21:09:06 to 2023年11月26日 04:58:06: ~7.82 hours</li>
99+
</ul>
100+
Total for server 4: ~20.52 hours</li>
101+
<li>For server ID 5:
102+
<ul>
103+
<li>From 2023年11月16日 19:42:22 to 2023年11月16日 21:08:22: ~1.43 hours</li>
104+
</ul>
105+
Total for server 5: ~1.43 hours</li>
106+
</ul>
107+
The accumulated runtime for all servers totals approximately 44.46 hours, equivalent to one full day plus some additional hours. However, since we consider only full days, the final output is rounded to 1 full day.</div>
108+
109+
## 解法
110+
111+
### 方法一
112+
113+
<!-- tabs:start -->
114+
115+
```sql
116+
117+
```
118+
119+
<!-- tabs:end -->
120+
121+
<!-- end -->
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# [3126. Server Utilization Time](https://leetcode.com/problems/server-utilization-time)
2+
3+
[中文文档](/solution/3100-3199/3126.Server%20Utilization%20Time/README.md)
4+
5+
<!-- tags: -->
6+
7+
## Description
8+
9+
<p>Table: <code>Servers</code></p>
10+
11+
<pre>
12+
+----------------+----------+
13+
| Column Name | Type |
14+
+----------------+----------+
15+
| server_id | int |
16+
| status_time | datetime |
17+
| session_status | enum |
18+
+----------------+----------+
19+
(server_id, status_time, session_status) is the primary key (combination of columns with unique values) for this table.
20+
session_status is an ENUM (category) type of (&#39;start&#39;, &#39;stop&#39;).
21+
Each row of this table contains server_id, status_time, and session_status.
22+
</pre>
23+
24+
<p>Write a solution to find the <strong>total time</strong> when servers were <strong>running</strong>. The output should be in units of <strong>full days</strong>.</p>
25+
26+
<p>Return <em>the result table in <strong>any</strong></em><em>&nbsp;order.</em></p>
27+
28+
<p>The result format is in the following example.</p>
29+
30+
<p>&nbsp;</p>
31+
<p><strong class="example">Example:</strong></p>
32+
33+
<div class="example-block">
34+
<p><strong>Input:</strong></p>
35+
36+
<p>Servers table:</p>
37+
38+
<pre class="example-io">
39+
+-----------+---------------------+----------------+
40+
| server_id | status_time | session_status |
41+
+-----------+---------------------+----------------+
42+
| 3 | 2023年11月04日 16:29:47 | start |
43+
| 3 | 2023年11月05日 01:49:47 | stop |
44+
| 3 | 2023年11月25日 01:37:08 | start |
45+
| 3 | 2023年11月25日 03:50:08 | stop |
46+
| 1 | 2023年11月13日 03:05:31 | start |
47+
| 1 | 2023年11月13日 11:10:31 | stop |
48+
| 4 | 2023年11月29日 15:11:17 | start |
49+
| 4 | 2023年11月29日 15:42:17 | stop |
50+
| 4 | 2023年11月20日 00:31:44 | start |
51+
| 4 | 2023年11月20日 07:03:44 | stop |
52+
| 1 | 2023年11月20日 00:27:11 | start |
53+
| 1 | 2023年11月20日 01:41:11 | stop |
54+
| 3 | 2023年11月04日 23:16:48 | start |
55+
| 3 | 2023年11月05日 01:15:48 | stop |
56+
| 4 | 2023年11月30日 15:09:18 | start |
57+
| 4 | 2023年11月30日 20:48:18 | stop |
58+
| 4 | 2023年11月25日 21:09:06 | start |
59+
| 4 | 2023年11月26日 04:58:06 | stop |
60+
| 5 | 2023年11月16日 19:42:22 | start |
61+
| 5 | 2023年11月16日 21:08:22 | stop |
62+
+-----------+---------------------+----------------+
63+
</pre>
64+
65+
<p><strong>Output:</strong></p>
66+
67+
<pre class="example-io">
68+
+-------------------+
69+
| total_uptime_days |
70+
+-------------------+
71+
| 1 |
72+
+-------------------+
73+
</pre>
74+
75+
<p><strong>Explanation:</strong></p>
76+
77+
<ul>
78+
<li>For server ID 3:
79+
<ul>
80+
<li>From 2023年11月04日 16:29:47 to 2023年11月05日 01:49:47: ~9.3 hours</li>
81+
<li>From 2023年11月25日 01:37:08 to 2023年11月25日 03:50:08: ~2.2 hours</li>
82+
<li>From 2023年11月04日 23:16:48 to 2023年11月05日 01:15:48: ~1.98 hours</li>
83+
</ul>
84+
Total for server 3: ~13.48 hours</li>
85+
<li>For server ID 1:
86+
<ul>
87+
<li>From 2023年11月13日 03:05:31 to 2023年11月13日 11:10:31: ~8 hours</li>
88+
<li>From 2023年11月20日 00:27:11 to 2023年11月20日 01:41:11: ~1.23 hours</li>
89+
</ul>
90+
Total for server 1: ~9.23 hours</li>
91+
<li>For server ID 4:
92+
<ul>
93+
<li>From 2023年11月29日 15:11:17 to 2023年11月29日 15:42:17: ~0.52 hours</li>
94+
<li>From 2023年11月20日 00:31:44 to 2023年11月20日 07:03:44: ~6.53 hours</li>
95+
<li>From 2023年11月30日 15:09:18 to 2023年11月30日 20:48:18: ~5.65 hours</li>
96+
<li>From 2023年11月25日 21:09:06 to 2023年11月26日 04:58:06: ~7.82 hours</li>
97+
</ul>
98+
Total for server 4: ~20.52 hours</li>
99+
<li>For server ID 5:
100+
<ul>
101+
<li>From 2023年11月16日 19:42:22 to 2023年11月16日 21:08:22: ~1.43 hours</li>
102+
</ul>
103+
Total for server 5: ~1.43 hours</li>
104+
</ul>
105+
The accumulated runtime for all servers totals approximately 44.46 hours, equivalent to one full day plus some additional hours. However, since we consider only full days, the final output is rounded to 1 full day.</div>
106+
107+
## Solutions
108+
109+
### Solution 1
110+
111+
<!-- tabs:start -->
112+
113+
```sql
114+
115+
```
116+
117+
<!-- tabs:end -->
118+
119+
<!-- end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /