Skip to content

Commit 27cef69

Browse files
committedApr 17, 2023
feat: update solutions to lc problem: No.2409
No.2409.Count Days Spent Together
1 parent 7087ec1 commit 27cef69

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed
 

‎solution/2400-2499/2409.Count Days Spent Together/README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848

4949
**方法一:模拟**
5050

51-
将日期转换为天数,然后计算两个人在罗马的天数。
51+
我们将日期转换为天数,然后计算两个人在罗马的天数。
5252

53-
时间复杂度 $O(1)$
53+
时间复杂度 $O(C)$,空间复杂度 $O(C)$。其中 $C$ 为常数
5454

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

@@ -61,14 +61,12 @@
6161
```python
6262
class Solution:
6363
def countDaysTogether(self, arriveAlice: str, leaveAlice: str, arriveBob: str, leaveBob: str) -> int:
64-
if leaveAlice < arriveBob or leaveBob < arriveAlice:
65-
return 0
6664
a = max(arriveAlice, arriveBob)
6765
b = min(leaveAlice, leaveBob)
68-
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
66+
days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
6967
x = sum(days[:int(a[:2]) - 1]) + int(a[3:])
7068
y = sum(days[:int(b[:2]) - 1]) + int(b[3:])
71-
return y - x + 1
69+
return max(y - x + 1, 0)
7270
```
7371

7472
### **Java**

‎solution/2400-2499/2409.Count Days Spent Together/README_EN.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@
4747
```python
4848
class Solution:
4949
def countDaysTogether(self, arriveAlice: str, leaveAlice: str, arriveBob: str, leaveBob: str) -> int:
50-
if leaveAlice < arriveBob or leaveBob < arriveAlice:
51-
return 0
5250
a = max(arriveAlice, arriveBob)
5351
b = min(leaveAlice, leaveBob)
54-
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
52+
days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
5553
x = sum(days[:int(a[:2]) - 1]) + int(a[3:])
5654
y = sum(days[:int(b[:2]) - 1]) + int(b[3:])
57-
return y - x + 1
55+
return max(y - x + 1, 0)
5856
```
5957

6058
### **Java**

‎solution/2400-2499/2409.Count Days Spent Together/Solution.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ class Solution:
22
def countDaysTogether(
33
self, arriveAlice: str, leaveAlice: str, arriveBob: str, leaveBob: str
44
) -> int:
5-
if leaveAlice < arriveBob or leaveBob < arriveAlice:
6-
return 0
75
a = max(arriveAlice, arriveBob)
86
b = min(leaveAlice, leaveBob)
9-
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
7+
days = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
108
x = sum(days[: int(a[:2]) - 1]) + int(a[3:])
119
y = sum(days[: int(b[:2]) - 1]) + int(b[3:])
12-
return y - x + 1
10+
return max(y - x + 1, 0)

‎solution/2400-2499/2414.Length of the Longest Alphabetical Continuous Substring/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
**方法一:双指针**
4848

49-
利用双指针 $i$ 和 $j$分别指向当前连续子字符串的起始位置和结束位置。遍历字符串 $s$,如果当前字符 $s[j]$ 比 $s[j-1]$ 大,则 $j$ 向右移动一位,否则更新 $i$ 为 $j$,并更新最长连续子字符串的长度。
49+
我们用双指针 $i$ 和 $j$ 分别指向当前连续子字符串的起始位置和结束位置。遍历字符串 $s$,如果当前字符 $s[j]$ 比 $s[j-1]$ 大,则 $j$ 向右移动一位,否则更新 $i$ 为 $j$,并更新最长连续子字符串的长度。
5050

5151
时间复杂度 $O(n)$,空间复杂度 $O(1)$。其中 $n$ 为字符串 $s$ 的长度。
5252

0 commit comments

Comments
 (0)