如何在整数数组中找到第二高的数字?
这是一个很好的实现吗?
有一个更好的方法吗?
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)