zoukankan      html  css  js  c++  java
  • minimum-number-of-arrows-to-burst-balloons(还挺好)

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

    与会议室排期问题,很相似。

    package com.company;
    
    import java.util.*;
    
    class Balloon {
        int[] points;
        boolean check;
        Balloon(int s, int e) {
            points = new int[2];
            points[0] = s;
            points[1] = e;
            check = false;
        }
    }
    
    class MyComparator implements Comparator<Balloon> {
    
        int index;
        MyComparator(int i) {
            index = i;
        }
    
        @Override
        public int compare(Balloon o1, Balloon o2) {
            return o1.points[index] - o2.points[index];
        }
    }
    
    class Solution {
        public int findMinArrowShots(int[][] points) {
            List<Balloon> endList = new ArrayList<>();
            List<Balloon> startList = new ArrayList<>();
    
            for (int i=0; i<points.length; i++) {
                Balloon balloon = new Balloon(points[i][0], points[i][1]);
                endList.add(balloon);
                startList.add(balloon);
            }
            Collections.sort(endList, new MyComparator(1));
            Collections.sort(startList, new MyComparator(0));
    
            int index = 0;
            int ret = 0;
            Iterator<Balloon> iter = endList.iterator();
            while (iter.hasNext()) {
                Balloon tmp = iter.next();
                if (tmp.check) {
                    continue;
                }
                ret++;
                while (index < points.length && startList.get(index).points[0] <= tmp.points[1]) {
                    startList.get(index).check = true;
                    index++;
                }
            }
            return ret;
        }
    }
    
    public class Main {
    
        public static void main(String[] args) throws InterruptedException {
    
            System.out.println("Hello!");
            Solution solution = new Solution();
    
            // Your Codec object will be instantiated and called as such:
            int[][] points = {{10,16}, {2,8}, {1,6}, {7,12}};
            int ret = solution.findMinArrowShots(points);
            System.out.printf("ret:%d
    ", ret);
    
            System.out.println();
    
        }
    
    }
  • 相关阅读:
    提取RDLC reporting相关dll的方式,打包客户端时需要用
    VS2012程序打包部署详解
    快速打包你的应用程序——Inno Setup
    "RDLC"报表-参数传递及主从报表
    如何在多个页中显示行标题和列标题 (Reporting Services)
    编译cocos2d-x 4.0版本
    2080Ti评测结果
    (转)u3d设计模式
    java基础知识(一)
    Java8新特性学习(一)--lambda表达式
  • 原文地址:https://www.cnblogs.com/charlesblc/p/6039837.html
Copyright © 2011-2022 走看看