小编use*_*790的帖子

如何在整数数组中找到第二高的数字?

如何在整数数组中找到第二高的数字?

这是一个很好的实现吗?

有一个更好的方法吗?

public class Find2ndHighest {
    public static void main(String[] args) {
        int b[] = {2,3,1,0,5};

        TreeMap<Integer,Integer> tree = new TreeMap<Integer,Integer>();
        for(int i = 0; i<b.length;i++){
            tree.put(b[i], 0);
        }
        System.out.println(tree.floorKey(tree.lastKey()-1));
    }
}
Run Code Online (Sandbox Code Playgroud)

java algorithm treemap

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

algorithm ×1

java ×1

treemap ×1