Skip to content

Commit 5eb4cd2

Browse files
authored
update: 添加问题“3169.无需开会的工作日”的代码和题解(#1012)
* docs: jp git branch -D 2099 已删除分支 2099(曾为 23b6ee8) Signed-off-by: LetMeFly666 <[email protected]> * docs: en 2025.7.8 * fix: strange en words traceback: #1003 x x ab5c736 |stillness| 681de37 * words: en+jp (yesterday) Signed-off-by: LetMeFly666 <[email protected]> * 3269: init (#1011) Signed-off-by: LetMeFly666 <[email protected]> * 3269: wa.cpp (#1011) Signed-off-by: LetMeFly666 <[email protected]> * 3269: wa.cpp (#1011) Signed-off-by: LetMeFly666 <[email protected]> * 3269: AC.cpp (#1011) AC,5.02%,5.02% Signed-off-by: LetMeFly666 <[email protected]> * words: jp words (#1011) Signed-off-by: LetMeFly666 <[email protected]> * 3169: begin.py (#1011) Signed-off-by: LetMeFly666 <[email protected]> * 3169: ac.py (#1011) AC,32.88%,96.40% Signed-off-by: LetMeFly666 <[email protected]> * 3169: RE.java (#1011) Signed-off-by: LetMeFly666 <[email protected]> * 3169: RE.java (#1011) Signed-off-by: LetMeFly666 <[email protected]> * 3169: RE.java (#1011) Signed-off-by: LetMeFly666 <[email protected]> * 3169: RE.java (#1011) Signed-off-by: LetMeFly666 <[email protected]> * 3169: AC.java (#1011) AC,74.09%,61.14% Signed-off-by: LetMeFly666 <[email protected]> * 3169: AC.go (#1011) AC,79.73%,72.97% Signed-off-by: LetMeFly666 <[email protected]> * 3169: init.docs (#1011) Signed-off-by: LetMeFly666 <[email protected]> * update: 添加问题“3169.无需开会的工作日”的代码和题解(#1012) Signed-off-by: LetMeFly666 <[email protected]> * fix: jp words https://github.com/LetMeFly666/LeetCode/pull/1012\#discussion_r2202717613 Signed-off-by: LetMeFly666 <[email protected]> * words: en(+jp) (#1011) Signed-off-by: LetMeFly666 <[email protected]> --------- Signed-off-by: LetMeFly666 <[email protected]>
1 parent 15ad0b3 commit 5eb4cd2

8 files changed

+304
-4
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-11 23:25:31
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-11 23:33:35
6+
*/
7+
#if defined(_WIN32) || defined(__APPLE__)
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int countDays(int days, vector<vector<int>>& meetings) {
14+
sort(meetings.begin(), meetings.end());
15+
int ans = 0;
16+
int last = 0;
17+
for (vector<int> me : meetings) {
18+
// printf("last = %d, me = [%d, %d]\n", last, me[0], me[1]);
19+
if (me[0] > last + 1) {
20+
ans += me[0] - last - 1;
21+
// printf("ans += %d\n", me[0] - last - 1);
22+
}
23+
last = max(last, me[1]);
24+
}
25+
ans += days - last;
26+
return ans;
27+
}
28+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-11 23:25:31
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-12 17:00:47
6+
*/
7+
package main
8+
9+
import "slices"
10+
11+
func countDays(days int, meetings [][]int) (ans int) {
12+
last := 0
13+
slices.SortFunc(meetings, func(a, b []int) int {return a[0] - b[0]})
14+
for _, me := range meetings {
15+
if me[0] > last + 1 {
16+
ans += me[0] - last - 1
17+
}
18+
last = max(last, me[1])
19+
}
20+
ans += days - last
21+
return
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2025-07-11 23:25:31
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2025-07-12 16:58:44
6+
*/
7+
import java.util.Arrays;
8+
9+
class Solution {
10+
public int countDays(int days, int[][] meetings) {
11+
int ans = 0;
12+
int last = 0;
13+
Arrays.sort(meetings, (a, b) -> a[0] - b[0]);
14+
for (int[] me : meetings) {
15+
if (me[0] > last + 1) {
16+
ans += me[0] - last - 1;
17+
}
18+
last = Math.max(last, me[1]);
19+
}
20+
ans += days - last;
21+
return ans;
22+
}
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2025-07-11 23:25:31
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2025-07-12 12:00:22
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def countDays(self, days: int, meetings: List[List[int]]) -> int:
11+
ans = last = 0
12+
meetings.sort()
13+
for l, r in meetings:
14+
if l > last + 1:
15+
ans += l - last - 1
16+
last = max(last, r)
17+
ans += days - last
18+
return ans

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@
939939
|3162.优质数对的总数I|简单|<a href="https://leetcode.cn/problems/find-the-number-of-good-pairs-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/10/LeetCode%203162.%E4%BC%98%E8%B4%A8%E6%95%B0%E5%AF%B9%E7%9A%84%E6%80%BB%E6%95%B0I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/142818980" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-number-of-good-pairs-i/solutions/2945122/letmefly-3162you-zhi-shu-dui-de-zong-shu-5p4r/" target="_blank">LeetCode题解</a>|
940940
|3164.优质数对的总数II|中等|<a href="https://leetcode.cn/problems/find-the-number-of-good-pairs-ii/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/11/LeetCode%203164.%E4%BC%98%E8%B4%A8%E6%95%B0%E5%AF%B9%E7%9A%84%E6%80%BB%E6%95%B0II/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/142865441" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-number-of-good-pairs-ii/solutions/2947224/letmefly-3164you-zhi-shu-dui-de-zong-shu-px67/" target="_blank">LeetCode题解</a>|
941941
|3165.不包含相邻元素的子序列的最大和|困难|<a href="https://leetcode.cn/problems/maximum-sum-of-subsequence-with-non-adjacent-elements/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/11/02/LeetCode%203165.%E4%B8%8D%E5%8C%85%E5%90%AB%E7%9B%B8%E9%82%BB%E5%85%83%E7%B4%A0%E7%9A%84%E5%AD%90%E5%BA%8F%E5%88%97%E7%9A%84%E6%9C%80%E5%A4%A7%E5%92%8C/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143452715" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/maximum-sum-of-subsequence-with-non-adjacent-elements/solutions/2974857/letmefly-3165bu-bao-han-xiang-lin-yuan-s-iih5/" target="_blank">LeetCode题解</a>|
942+
|3169.无需开会的工作日|中等|<a href="https://leetcode.cn/problems/count-days-without-meetings/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/07/11/LeetCode%203169.%E6%97%A0%E9%9C%80%E5%BC%80%E4%BC%9A%E7%9A%84%E5%B7%A5%E4%BD%9C%E6%97%A5/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/149301503" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-days-without-meetings/solutions/3722181/letmefly-3169wu-xu-kai-hui-de-gong-zuo-r-x51x/" target="_blank">LeetCode题解</a>|
942943
|3174.清除数字|简单|<a href="https://leetcode.cn/problems/clear-digits/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/09/05/LeetCode%203174.%E6%B8%85%E9%99%A4%E6%95%B0%E5%AD%97/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/141943628" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/clear-digits/solutions/2906472/letmefly-3174qing-chu-shu-zi-yi-ge-bu-yo-e3l4/" target="_blank">LeetCode题解</a>|
943944
|3175.找到连续赢K场比赛的第一位玩家|中等|<a href="https://leetcode.cn/problems/find-the-first-player-to-win-k-games-in-a-row/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/10/24/LeetCode%203175.%E6%89%BE%E5%88%B0%E8%BF%9E%E7%BB%AD%E8%B5%A2K%E5%9C%BA%E6%AF%94%E8%B5%9B%E7%9A%84%E7%AC%AC%E4%B8%80%E4%BD%8D%E7%8E%A9%E5%AE%B6/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/143206596" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-first-player-to-win-k-games-in-a-row/solutions/2963380/letmefly-3175zhao-dao-lian-xu-ying-k-cha-qon3/" target="_blank">LeetCode题解</a>|
944945
|3176.求出最长好子序列I|中等|<a href="https://leetcode.cn/problems/find-the-maximum-length-of-a-good-subsequence-i/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/09/07/LeetCode%203176.%E6%B1%82%E5%87%BA%E6%9C%80%E9%95%BF%E5%A5%BD%E5%AD%90%E5%BA%8F%E5%88%97I/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/141992543" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-the-maximum-length-of-a-good-subsequence-i/solutions/2907809/letmefly-3176qiu-chu-zui-chang-hao-zi-xu-6lx5/" target="_blank">LeetCode题解</a>|
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
---
2+
title: 3169.无需开会的工作日:排序+一次遍历——不需要正难则反,因为正着根本不难
3+
date: 2025-07-12 22:33:58
4+
tags: [题解, LeetCode, 中等, 数组, 排序]
5+
categories: [题解, LeetCode]
6+
---
7+
8+
# 【LetMeFly】3169.无需开会的工作日:排序+一次遍历——不需要正难则反,因为正着根本不难
9+
10+
力扣题目链接:[https://leetcode.cn/problems/count-days-without-meetings/](https://leetcode.cn/problems/count-days-without-meetings/)
11+
12+
<p>给你一个正整数 <code>days</code>,表示员工可工作的总天数(从第 1 天开始)。另给你一个二维数组 <code>meetings</code>,长度为 <code>n</code>,其中 <code>meetings[i] = [start_i, end_i]</code> 表示第 <code>i</code> 次会议的开始和结束天数(包含首尾)。</p>
13+
14+
<p>返回员工可工作且没有安排会议的天数。</p>
15+
16+
<p><strong>注意:</strong>会议时间可能会有重叠。</p>
17+
18+
<p>&nbsp;</p>
19+
20+
<p><strong class="example">示例 1:</strong></p>
21+
22+
<div class="example-block">
23+
<p><strong>输入:</strong><span class="example-io">days = 10, meetings = [[5,7],[1,3],[9,10]]</span></p>
24+
25+
<p><strong>输出:</strong><span class="example-io">2</span></p>
26+
27+
<p><strong>解释:</strong></p>
28+
29+
<p>第 4 天和第 8 天没有安排会议。</p>
30+
</div>
31+
32+
<p><strong class="example">示例 2:</strong></p>
33+
34+
<div class="example-block">
35+
<p><strong>输入:</strong><span class="example-io">days = 5, meetings = [[2,4],[1,3]]</span></p>
36+
37+
<p><strong>输出:</strong><span class="example-io">1</span></p>
38+
39+
<p><strong>解释:</strong></p>
40+
41+
<p>第 5 天没有安排会议。</p>
42+
</div>
43+
44+
<p><strong class="example">示例 3:</strong></p>
45+
46+
<div class="example-block">
47+
<p><strong>输入:</strong><span class="example-io">days = 6, meetings = [[1,6]]</span></p>
48+
49+
<p><strong>输出:</strong>0</p>
50+
51+
<p><strong>解释:</strong></p>
52+
53+
<p>所有工作日都安排了会议。</p>
54+
</div>
55+
56+
<p>&nbsp;</p>
57+
58+
<p><strong>提示:</strong></p>
59+
60+
<ul>
61+
<li><code>1 &lt;= days &lt;= 10<sup>9</sup></code></li>
62+
<li><code>1 &lt;= meetings.length &lt;= 10<sup>5</sup></code></li>
63+
<li><code>meetings[i].length == 2</code></li>
64+
<li><code>1 &lt;= meetings[i][0] &lt;= meetings[i][1] &lt;= days</code></li>
65+
</ul>
66+
67+
好奇,怎么都在说正难则反。
68+
69+
## 解题方法:排序
70+
71+
只需要按照meetings开始的顺序从小到大排序,使用一个变量(last)记录上次会议的结束日期(初始值为0),接着开始遍历meetings数组。
72+
73+
如果开始时间比last晚不只一天,就说明从last到这个开始时间都有空,累加到答案中。每遍历完一个meeting,就将last更新为last和meeting结束时间的最大值。
74+
75+
最终,days-last也是空闲时间,累加到答案中。
76+
77+
+ 时间复杂度$O(n\log n)$,其中$n=len(meetings)$。
78+
+ 空间复杂度$O(\log n)$
79+
80+
### AC代码
81+
82+
#### C++
83+
84+
```cpp
85+
/*
86+
* @Author: LetMeFly
87+
* @Date: 2025-07-11 23:25:31
88+
* @LastEditors: LetMeFly.xyz
89+
* @LastEditTime: 2025-07-11 23:33:35
90+
*/
91+
class Solution {
92+
public:
93+
int countDays(int days, vector<vector<int>>& meetings) {
94+
sort(meetings.begin(), meetings.end());
95+
int ans = 0;
96+
int last = 0;
97+
for (vector<int> me : meetings) {
98+
// printf("last = %d, me = [%d, %d]\n", last, me[0], me[1]);
99+
if (me[0] > last + 1) {
100+
ans += me[0] - last - 1;
101+
// printf("ans += %d\n", me[0] - last - 1);
102+
}
103+
last = max(last, me[1]);
104+
}
105+
ans += days - last;
106+
return ans;
107+
}
108+
};
109+
```
110+
111+
#### Python
112+
113+
```python
114+
'''
115+
Author: LetMeFly
116+
Date: 2025-07-11 23:25:31
117+
LastEditors: LetMeFly.xyz
118+
LastEditTime: 2025-07-12 12:00:22
119+
'''
120+
from typing import List
121+
122+
class Solution:
123+
def countDays(self, days: int, meetings: List[List[int]]) -> int:
124+
ans = last = 0
125+
meetings.sort()
126+
for l, r in meetings:
127+
if l > last + 1:
128+
ans += l - last - 1
129+
last = max(last, r)
130+
ans += days - last
131+
return ans
132+
```
133+
134+
#### Java
135+
136+
```java
137+
/*
138+
* @Author: LetMeFly
139+
* @Date: 2025-07-11 23:25:31
140+
* @LastEditors: LetMeFly.xyz
141+
* @LastEditTime: 2025-07-12 16:58:44
142+
*/
143+
import java.util.Arrays;
144+
145+
class Solution {
146+
public int countDays(int days, int[][] meetings) {
147+
int ans = 0;
148+
int last = 0;
149+
Arrays.sort(meetings, (a, b) -> a[0] - b[0]);
150+
for (int[] me : meetings) {
151+
if (me[0] > last + 1) {
152+
ans += me[0] - last - 1;
153+
}
154+
last = Math.max(last, me[1]);
155+
}
156+
ans += days - last;
157+
return ans;
158+
}
159+
}
160+
```
161+
162+
#### Go
163+
164+
```go
165+
/*
166+
* @Author: LetMeFly
167+
* @Date: 2025-07-11 23:25:31
168+
* @LastEditors: LetMeFly.xyz
169+
* @LastEditTime: 2025-07-12 17:00:47
170+
*/
171+
package main
172+
173+
import "slices"
174+
175+
func countDays(days int, meetings [][]int) (ans int) {
176+
last := 0
177+
slices.SortFunc(meetings, func(a, b []int) int {return a[0] - b[0]})
178+
for _, me := range meetings {
179+
if me[0] > last + 1 {
180+
ans += me[0] - last - 1
181+
}
182+
last = max(last, me[1])
183+
}
184+
ans += days - last
185+
return
186+
}
187+
```
188+
189+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/149301503)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2025/07/11/LeetCode%203169.%E6%97%A0%E9%9C%80%E5%BC%80%E4%BC%9A%E7%9A%84%E5%B7%A5%E4%BD%9C%E6%97%A5/)哦~
190+
>
191+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/Other-English-LearningNotes-SomeWords.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,8 +1268,8 @@ categories: [自用]
12681268
|||
12691269
|wring|v. 拧(水)<details><summary>过去分词</summary>wrung</details>|
12701270
|typist|n. 打字员,打字者|
1271-
|creek|n. 小溪| x x
1272-
stillnessn. 静止,沉静
1271+
|creek|n. 小溪|
1272+
|stillness|n. 静止,沉静|
12731273
|utterance|n. 话语,说话,用语言的表达,言论|
12741274
|||
12751275
|fortress|n. 堡垒,要塞,防御工作|
@@ -1279,6 +1279,15 @@ categories: [自用]
12791279
|petty|adj. 琐碎的,微不足道的,小气的|
12801280
|agony|n. 极度痛苦|
12811281
|detour|n. 绕道,绕行路<br/>v. 迂回,绕道|
1282+
|||
1283+
|dent|n. 凹痕<br/>v. 使...凹陷,挫伤,损害(信心等)|
1284+
|||
1285+
|cutlery|n. 刀叉勺|
1286+
|indicative|adj. 表示的,显示的,暗示的,象征的,陈述的,指示的<br/>n. 陈述语句<details><summary>例句</summary>Their failure to act is <font color="#28bea0">indicative</font> of their lack of interest.<br/>他们未采取行动,这表示他们没有兴趣。</details>|
1287+
|creditworthiness(credit·worthy·ness)|n. 信贷价值,信誉|
1288+
|||
1289+
|dodge|v. 闪避,躲开<br/>n. 推脱的计策,逃避的诡计,骗人的伎俩|
1290+
|suburban|adj. 郊区的,城外的,平淡乏味的,呆板的<br/>n. 〈美〉郊区居民|
12821291

12831292
<p class="wordCounts">单词收录总数</p>
12841293

Solutions/Other-Japanese-LearningNotes.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ xx型
160160
|書き(かき)||
161161
|調べ(しらべ)|查找|
162162
|買い(かい)||
163+
|入れ(いれ)|预约(v.)|
164+
|予約(よやく)|预约(n.)|
163165
|払い(はらい)||
164166
|返す(かえす)|还(huán)|
165167
|貸し(かし)|借(给)|
@@ -358,6 +360,7 @@ xx型
358360
|重い(おもい)|重的|
359361
|可愛い(かわいい)|可爱的|
360362
|うるさい|吵的|
363+
|最高(さいこう)|最棒的|
361364
|綺麗(きれい)|漂亮的/干净的(环境/物品)|
362365
|美しい(うつくしい)|优雅的(艺术/心灵/自然)|
363366
|(ダサく)|土气的/不酷的|
@@ -377,7 +380,9 @@ xx型
377380
|危ない(あぶない)|危险的|
378381
|同じ(おなじ)|一样的|
379382
|ゆっくり|慢慢|
383+
|苦手(にがて)|不擅长/不喜欢|
380384
|よい||
385+
|やったー|太好了|
381386
|強い(つよい)|厉害的|
382387
|弱い(よわい)|弱的|
383388
|おしゃれ|时尚/时髦的|
@@ -513,6 +518,7 @@ xx型
513518
|買い物(かいもの)|购物(购买的商品)|
514519
|傘(かさ)||
515520
|ドア||
521+
|場所(ばしょ)|场所|
516522
|壁(かべ)||
517523
|花(はな)||
518524
|景色(けしき)|景色/风景|
@@ -957,6 +963,8 @@ xx型
957963
|||
958964
|牛肉(ぎゅうにく)|牛肉|
959965
|豚肉(ぶたにく)|猪肉|
966+
|ベジタリアン(vegetarian)|素食者|
967+
|生(なま)|生的|
960968

961969
## 小句
962970

@@ -1386,8 +1394,8 @@ xx型
13861394
|もっと小さい茶碗はありますか?<br/>有更小的碗吗?|
13871395
|両親は日本語ができます。<br/>我父母会说日语。|
13881396
|人気のレストラン。<br/>受欢迎的餐厅。|
1389-
|<br/>|
1390-
|<br/>|
1397+
|予約をいれましょう。<br/>我们来预约吧!|
1398+
|八時に予約を入れます。<br/>我预约在8点。|
13911399
|<br/>|
13921400
|<br/>|
13931401
|<br/>|

0 commit comments

Comments
 (0)