奇安信笔试

  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
    delete不会删除表,且可以作用于单条或多条数据,truncate是清空表,包括索引
    delete要维护undo日志,truncate效率比delete高
    编程
  7. 分钱:老板可以一次分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());
}

}

转载:https://blog.nowcoder.net/n/c96ee140f54e4e55b8fd2691eff6c16a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值