Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3de8ab

Browse files
authored
Update 759-employee-free-time.js
1 parent 88accd7 commit b3de8ab

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

759-employee-free-time.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,35 @@ const employeeFreeTime = function(schedule) {
113113
}
114114
return res
115115
}
116+
117+
// another
118+
119+
/**
120+
* // Definition for an Interval.
121+
* function Interval(start, end) {
122+
* this.start = start;
123+
* this.end = end;
124+
* };
125+
*/
126+
127+
/**
128+
* @param {Interval[][]} schedule
129+
* @return {Interval[]}
130+
*/
131+
const employeeFreeTime = function (schedule) {
132+
const res = [], timeLine = []
133+
schedule.forEach(e => timeLine.push(...e))
134+
timeLine.sort((a, b) => a.start - b.start)
135+
let tmp = timeLine[0]
136+
for(let i = 1, n = timeLine.length; i < n; i++) {
137+
const el = timeLine[i]
138+
if(el.start > tmp.end) {
139+
res.push(new Interval(tmp.end, el.start))
140+
tmp = el
141+
} else {
142+
tmp = el.end > tmp.end ? el : tmp
143+
}
144+
}
145+
return res
146+
}
147+

0 commit comments

Comments
 (0)