package com.hzs.common.core.utils;

import java.text.DecimalFormat;
import java.util.*;

/**
 * @Description:
 * @Author: yuhui
 * @Time: 2022/12/2 14:12
 * @Classname: NumberUtil
 * @PackageName: com.hzs.common.core.utils
 */
public class NumberUtil {

    /**
     * 获取百分比
     * @param number1 /
     * @param number2 总数/
     * @return java.lang.String /
     * @date 2022/5/30 14:48
     */
    public static String getRatio(Integer number1, Integer number2) {
        DecimalFormat df = new DecimalFormat("0.0");
        if (number2 != 0) {
            return df.format((float) (number1 / (double) number2) * 100) + "%";
        } else {
            return "0%";
        }
    }

    /**
     * 给定无序数组 查找缺失的数字
     * @param numbers
     * @return
     */
    public static Set<Integer> findMissing(Set<Integer> numbers) {
        int max = 0;
        Set<Integer> result = new HashSet<>();
        Map<Integer,Integer> map = new HashMap<Integer,Integer>();

        for(Integer num : numbers) {
            if(num > max)
                max=num;
            map.put(num,num);
        }

        int missingCount=max-numbers.size();

        for(int i=1;i<=max;i++) {
            if(missingCount == 0) break;

            if(!map.containsKey(i)) {
                result.add(i);
                missingCount--;
            }

        }
        return result;
    }

    public static void main(String[] args) {
        Set<Integer> set = new HashSet<>();
        set.add(1);

        System.out.println(findMissing(set));
    }
}
