1. String s1 = new String("abc")创建了几个String对象

答:两个,s1引用放在栈,"abc"字符串在堆

2. epoll的两种模式,EL边缘模式和TL水平模式。epoll默认使用TL,TL支持非阻塞IO

3. MySQL删除一个视图命令:drop view viewName

4. 查找字符串公共前缀,用Trie前缀树(没听说过)

5. 守护线程和非守护线程:jvm会等待非守护线程结束,jvm不会等待守护线程结束。GC线程就是守护线程

6. truncate和delete

  1. delete不会删除表,且可以作用于单条或多条数据,truncate是清空表,包括索引
  2. delete要维护undo日志,truncate效率比delete高

编程

1. 分钱:老板可以一次分1元,也可以一次分2元,也可以一次分n元。求一共有几种方案。你以为能分n元?其实只能分1,2,3元哒!直接裂开来

    public static int CalulateMethodCount (int num_money) {
        // write code here

        int[] result = new int[num_money + 3];
        result[1] = 1;
        result[2] = 2;
        result[3] = 4;
        for (int i = 4; i <= num_money; i++) {
            result[i] = result[i - 1] + result[i - 2] + result[i - 3];
        }

        return result[num_money];
    }

2. 编辑和回退:输入一个字符串,当遇到"undo"时,删除前一个字符串,当遇到"redo"时,恢复上一个删除的字符串。没做出来,只过了20%,贴一个大佬的80%的答案。

//学到了:
//维护数组的增删,可用双栈实现

import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] str = sc.nextLine().split(" ");

        //双栈维护弹出和恢复

        Stack<String> redo = new Stack<>();
        Stack<String> undo = new Stack<>();

        for(int i=0;i<str.length;i++){
            //如果str[i]是undo,且redo栈不为空,undo栈存入redo的弹出
            if(str[i].equals("undo")){
                if(!redo.isEmpty()){
                    undo.push(redo.pop());
                }

                //如果str[i]是redo,且undo栈不为空,redo栈存入undo的弹出
            }else if(str[i].equals("redo")){
                if(!undo.isEmpty()){
                    redo.push(undo.pop());
                }
            }else{
                redo.push(str[i]);
            }
            //redo存入
        }

        String[] temp = new String[redo.size()];
        //因为弹出栈顶,所以数组倒序存入
        int index = temp.length-1;
        while(!redo.isEmpty()){
            temp[index] = redo.pop();
            --index;
        }

        StringBuilder result = new StringBuilder();
        for(int i=0;i<temp.length;i++){
            result.append(temp[i]+" ");
        }

        System.out.println(result.toString().trim());
    }
}