File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -145,3 +145,37 @@ const employeeFreeTime = function (schedule) {
145
145
return res
146
146
}
147
147
148
+ // another
149
+
150
+ /**
151
+ * // Definition for an Interval.
152
+ * function Interval(start, end) {
153
+ * this.start = start;
154
+ * this.end = end;
155
+ * };
156
+ */
157
+
158
+ /**
159
+ * @param {Interval[][] } schedule
160
+ * @return {Interval[] }
161
+ */
162
+ var employeeFreeTime = function ( schedule ) {
163
+ const arr = schedule . reduce ( ( ac , e ) => {
164
+ ac . push ( ...e )
165
+ return ac
166
+ } , [ ] )
167
+ arr . sort ( ( a , b ) => a . start - b . start || b . end - a . end )
168
+ const n = arr . length
169
+ const res = [ ]
170
+ let end = arr [ 0 ] . end
171
+ for ( let i = 1 ; i < n ; i ++ ) {
172
+ const cur = arr [ i ]
173
+ if ( cur . start > end ) {
174
+ res . push ( new Interval ( end , cur . start ) )
175
+ }
176
+
177
+ end = Math . max ( end , cur . end )
178
+ }
179
+
180
+ return res
181
+ } ;
You can’t perform that action at this time.
0 commit comments