Skip to content

Commit e1afc08

Browse files
committed
feat: update solutions to lc problems
1 parent 1446b7e commit e1afc08

File tree

7 files changed

+14
-13
lines changed

7 files changed

+14
-13
lines changed

solution/0700-0799/0729.My Calendar I/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ class MyCalendar:
6666

6767
def book(self, start: int, end: int) -> bool:
6868
idx = self.sd.bisect_right(start)
69-
if 0 <= idx < len(self.sd):
70-
if end > self.sd.values()[idx]:
71-
return False
69+
if idx < len(self.sd) and end > self.sd.values()[idx]:
70+
return False
7271
self.sd[end] = start
7372
return True
7473

solution/0700-0799/0729.My Calendar I/README_EN.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ class MyCalendar:
5858

5959
def book(self, start: int, end: int) -> bool:
6060
idx = self.sd.bisect_right(start)
61-
if 0 <= idx < len(self.sd):
62-
if end > self.sd.values()[idx]:
63-
return False
61+
if idx < len(self.sd) and end > self.sd.values()[idx]:
62+
return False
6463
self.sd[end] = start
6564
return True
6665

solution/0700-0799/0729.My Calendar I/Solution.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ def __init__(self):
77

88
def book(self, start: int, end: int) -> bool:
99
idx = self.sd.bisect_right(start)
10-
if 0 <= idx < len(self.sd):
11-
if end > self.sd.values()[idx]:
12-
return False
10+
if idx < len(self.sd) and end > self.sd.values()[idx]:
11+
return False
1312
self.sd[end] = start
1413
return True
1514

solution/1900-1999/1984.Minimum Difference Between Highest and Lowest of K Scores/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
<!-- 这里可写通用的实现逻辑 -->
5151

52-
排序。
52+
**方法一:排序**
5353

5454
<!-- tabs:start -->
5555

solution/2300-2399/2327.Number of People Aware of a Secret/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353

5454
**方法一:差分数组**
5555

56+
差分数组 $d[i]$ 记录每天知道秘密的人数变化情况,$cnt[i]$ 记录第 $i$ 天新得知秘密的人数。那么从 $[i+delay,i+forget)$ 的这段时间内,$cnt[i]$ 个人每天都能分享给另外 $cnt[i]$ 个人。
57+
58+
最终 $sum(d[:n+1])$ 就是答案。
59+
5660
时间复杂度 $O(n^2)$。
5761

5862
<!-- tabs:start -->
@@ -77,7 +81,7 @@ class Solution:
7781
cnt[nxt] += cnt[i]
7882
nxt += 1
7983
mod = 10**9 + 7
80-
return list(accumulate(d))[n] % mod
84+
return sum(d[: n + 1]) % mod
8185
```
8286

8387
### **Java**

solution/2300-2399/2327.Number of People Aware of a Secret/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Solution:
6767
cnt[nxt] += cnt[i]
6868
nxt += 1
6969
mod = 10**9 + 7
70-
return list(accumulate(d))[n] % mod
70+
return sum(d[: n + 1]) % mod
7171
```
7272

7373
### **Java**

solution/2300-2399/2327.Number of People Aware of a Secret/Solution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def peopleAwareOfSecret(self, n: int, delay: int, forget: int) -> int:
1313
cnt[nxt] += cnt[i]
1414
nxt += 1
1515
mod = 10**9 + 7
16-
return list(accumulate(d))[n] % mod
16+
return sum(d[: n + 1]) % mod

0 commit comments

Comments
 (0)