Skip to content

Commit 96158e0

Browse files
committed
https://leetcode.cn/problems/count-days-spent-together/
1 parent 30805bf commit 96158e0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/count-days-spent-together/
14+
1315
https://leetcode.cn/problems/reverse-odd-levels-of-binary-tree/
1416

1517
https://leetcode.cn/problems/smallest-even-multiple/

count-days-spent-together/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default function countDaysTogether(
2+
arriveAlice: string,
3+
leaveAlice: string,
4+
arriveBob: string,
5+
leaveBob: string,
6+
): number {
7+
const arrive = arriveAlice > arriveBob ? arriveAlice : arriveBob,
8+
leave = leaveAlice < leaveBob ? leaveAlice : leaveBob,
9+
base = (new Date(`2021-${leave}`).valueOf() -
10+
new Date(`2021-${arrive}`).valueOf()) /
11+
(24 * 60 * 60 * 1000) + 1;
12+
return Math.max(base, 0);
13+
}

0 commit comments

Comments
 (0)