Byte Beat-Interview Question Record

25. {Programming}-write a singleton mode, lazy man loads the
code design:

//单例模式 懒汉模式
public class Singleton {
    
    
    private static Singleton instance=null;

    private Singleton(){
    
    

    }
    public static Singleton newInstance(){
    
    //没有加锁 若并发调用时 可能会产生多个对象   优化synchronized

        if(instance==null){
    
    
            instance=new Singleton();
        }
        return  instance;
    }

}

26 {Programming}-Find the 10000 largest number from 100000000 unordered floating point numbers, requiring the lowest time complexity.
Problem solving idea:
Use the smallest heap (the priority queue realizes the smallest heap) to
insert the first 10000 elements into the priority queue, Then continue to traverse the remaining elements. During each traversal process, the value of the element is compared with the value of the head of the priority queue. If the value of the current element is greater than the value of the head of the priority queue, the value of the head of the priority queue is removed, and the current element Insert it, so you get the largest number of 10,000

Guess you like

Origin blog.csdn.net/fxwentian/article/details/115218552