百度一面

1重写与重载

重载和重写在语法上的区别:
重载:发生在同一个类中,方法名相同,特征签名不同(参数类型、个数、顺序);PS:不作为重载条件的额外限制:对方法的返回值和访问修饰符没有要求,可以相同可以不同,在编译期决定调用方法的版本(参下)。
重写:发生在父子类中,方法名、特征签名(参数列表)必须相同;PS:不作为重写条件的额外限制:返回值的范围小于等于父类;抛出的异常范围小于等于父类;访问修饰符范围大于等于父类;如果父类方法的访问修饰符为private则子类就不能重写。static方法不能重写,但可以隐藏。

2mysql索引

3链表中环的入口

public static Node find(Node node){
        if(node==null||node.next==null){
            return null;
        }
        Node slow=node,fast=node;
        while(fast!=null&&fast.next!=null){
           slow=slow.next;
           fast=fast.next.next;
           if(slow==fast){

               break;
           }
        }
        if(fast==null||fast.next==null)
            return null;
        while(node!=fast){
            node=node.next;
            fast=fast.next;
        }
        return node;
    }

证明:https://blog.csdn.net/u011373710/article/details/54024366

4无序数组第k大的数

public static int find(int a[],int k){

        int lo=0,hi=a.length-1;
        while(true){
            int j=partition(a,lo,hi);
            if(j==a.length-k){
                break;
            }else if(j>a.length-k){
                hi=j-1;
            }else{
              lo=j+1;
            }
        }
         return a[lo];
    }
    public static int partition(int a[],int lo,int hi){
        int i=lo,j=hi,pivot=a[lo];
        while(i<j){
            while(i<j&&a[j]>=pivot)j--;
            a[i]=a[j];
            while(i<j&&a[i]<=pivot)i++;
            a[j]=a[i];
        }
        a[i]=pivot;
        return i;
    }

5单例,工厂

简单工厂

public class OperatingFactory {
    public static Operation createOperation(String operate){
       Operation oper=null;
       switch(operate){
           case "+":
               oper=new OperationAdd();
               break;
           case "-":
               oper=new OperationSub();
               break;
       }
       return oper;
    }
    public static void main(String args[]){
        Operation oper=OperatingFactory.createOperation("+");
        oper.numbera=1;
        oper.numberb=2;
        int result=oper.getResult();
    }
}
abstract class  Operation{
    int numbera;
    int numberb;
    abstract int getResult();
}
class OperationAdd extends Operation{

     public int getResult(){
         return numbera+numberb;
     }
}
class OperationSub extends Operation{

    public int getResult(){
        return numbera-numberb;
    }
}

工厂方法

interface IFactory{
    Operation createOperation();
    
}
class AddFactory implements IFactory{
    public Operation createOperation(){
        return new OperationAdd();
    }
    public static void main(String args[]){
           IFactory iFactory=new AddFactory();
           Operation operation=iFactory.createOperation();
           operation.numbera=1;
           operation.numberb=2;
           int result=operation.getResult();
    }
}
class SubFactory implements IFactory{
    public Operation createOperation(){
        return new OperationSub();
    }
}

6项目redis,es

猜你喜欢

转载自blog.csdn.net/wuyifan1115/article/details/82723273