File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -113,3 +113,35 @@ const employeeFreeTime = function(schedule) {
113
113
}
114
114
return res
115
115
}
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
+
You can’t perform that action at this time.
0 commit comments