File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -209,3 +209,33 @@ class PriorityQueue {
209209    } 
210210  } 
211211} 
212+ 
213+ // another 
214+ /** 
215+  * @param  {number[][] } tasks 
216+  * @return  {number[] } 
217+  */ 
218+ const  getOrder  =  function ( tasks )  { 
219+   const  n  =  tasks . length 
220+   const  pq  =  new  PriorityQueue ( ( a ,  b )  =>  a [ 0 ]  ===  b [ 0 ]  ? a [ 1 ]  <  b [ 1 ]  : a [ 0 ]  <  b [ 0 ] ) 
221+   tasks . forEach ( ( e ,  i )  =>  e . push ( i ) ) 
222+   tasks . sort ( ( a ,  b )  =>  a [ 0 ]  -  b [ 0 ] ) 
223+   let  idx  =  0 ,  time  =  0 
224+   const  res  =  [ ] 
225+ 
226+   while ( idx  <  n  ||  ! pq . isEmpty ( ) )  { 
227+     while ( idx  <  n  &&  tasks [ idx ] [ 0 ]  <=  time )  { 
228+       pq . push ( [ tasks [ idx ] [ 1 ] ,  task [ idx ] [ 2 ] ] ) 
229+       idx ++ 
230+     } 
231+     if ( ! pq . isEmpty ( ) )  { 
232+       const  tmp  =  pq . pop ( ) 
233+       time  +=  tmp [ 0 ] 
234+       res . push ( tmp [ 1 ] ) 
235+     }  else  if ( idx  <  n )  { 
236+       time  =  tasks [ idx ] [ 0 ] 
237+     } 
238+   } 
239+   return  res 
240+ 
241+ } ; 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments