leetcode452

public class Solution {
    public int FindMinArrowShots(int[,] points)
        {
            // multidimensional array cannot be sorted directly - copy to objects
            Pt[] pts = new Pt[points.GetLength(0)];
            for (int i = 0; i < points.GetLength(0); i++)
            {
                pts[i] = new Pt(points[i, 0], points[i, 1]);
            }
            Array.Sort(pts, (a, b) => a.start.CompareTo(b.start));

            int cnt = 0;
            Pt prev = null;
            for (int i = 0; i < pts.Length; i++)
            {
                if (prev == null || prev.end < pts[i].start)
                {
                    cnt++;
                    prev = pts[i];
                }
                else if (pts[i].end < prev.end)
                {
                    prev.end = pts[i].end;
                }
            }
            return cnt;
        }

        public class Pt
        {
            public int start;
            public int end;
            public Pt(int s, int e) { start = s; end = e; }
        }
}

https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/#/solutions

原文地址:https://www.cnblogs.com/asenyang/p/6970181.html