Day 47: Buckle problem 452, detonate the balloon with the minimum number of arrows

Address: leetcode-cn.com/problems/mi…

Order by points[I][1] from smallest to largest. If the second item of the previous item is greater than or equal to the first item of the next item, then the total number of arrows is reduced by one. (Points [I][1] >= points[I + flag][0])

var findMinArrowShots = function(points) {
  points.sort((a, b) => a[1] - b[1]);
  let res = points.length;
  let flag = 1;
  for(let i = 0; i + flag < points.length; i++)
  {
    if(points[i][1] >= points[i + flag][0])
    {
      res--;
      flag++;
      i--;
    }
    else
    {
      i = i + flag - 1;
      flag = 1;
    }
  }
  return res;
};
Copy the code

Execution time: 124 ms, beating 83.03% of all JavaScript commits

Memory consumption: 44.6 MB, beating 46.95% of all JavaScript commits