public int Find(int[] nums, int k)
        {
            var minHeap = new MinHeap(k);

            foreach (var num in nums)
            {
                minHeap.Insert(num);
            }

            return(minHeap.PeekMin());
        }
Ejemplo n.º 2
0
        public int MinMeetingRooms(Interval[] intervals)
        {
            Array.Sort(intervals, new Comparison <Interval>((i1, i2) => i2.start.CompareTo(i1.start)));
            var rooms = new MinHeap(int.MaxValue);

            foreach (var interval in intervals)
            {
                if (rooms.PeekMin() <= interval.start)
                {
                    rooms.ExtractMin();
                    rooms.InsertKey(interval.end);
                }
                else
                {
                    rooms.InsertKey(interval.end);
                }
            }

            return(rooms._data.Count);
        }