Skip to content

Latest commit

 

History

History
22 lines (12 loc) · 697 Bytes

File metadata and controls

22 lines (12 loc) · 697 Bytes

Interval (1)

0. Number of Airplane in the sky.java Level: Medium Tags: [Array, Interval, PriorityQueue, Sort, Sweep Line]

Sweep Line

  • 把Interval拆分成数轴上的Point
  • 起飞mark 1
  • 降落mark -1
  • 用PriorityQueue排序, loop through queue, 计算(起飞+降落)值可能有的max。

注意

  • 同时起飞和降落,就是 1 - 1 = 0. 所以在while loop里面有第二个while loop,
  • 当坐标x重合时,在这里做完所有x点的加减,然后再比较 max。
  • 这避免了错误多count,或者少count