/*
* @lc app=leetcode.cn id=2446 lang=typescript
*
* [2446] 判断两个事件是否存在冲突
*/
// @lc code=start
function haveConflict(event1: string[], event2: string[]): boolean {}
// @lc code=end
function haveConflict(event1: string[], event2: string[]): boolean {
const [a, b, c, d] = [...event1, ...event2].map(s => new Date(`2000-01-01 ${s}`))
if (a <= c) {
return b >= c
} else {
return d >= a
}
}
test.each([
{ input: { event1: ['01:15', '02:00'], event2: ['02:00', '03:00'] }, output: true },
{ input: { event1: ['01:00', '02:00'], event2: ['01:20', '03:00'] }, output: true },
{ input: { event1: ['10:00', '11:00'], event2: ['14:00', '15:00'] }, output: false },
])('input: event1 = $input.event1, event2 = $input.event2', ({ input: { event1, event2 }, output }) => {
expect(haveConflict(event1, event2)).toEqual(output)
})