首页 > 字节2面(伪)凉经
头像
DennisLee
编辑于 2020-09-07 16:38
+ 关注

字节2面(伪)凉经

一面面试官人确实挺好的。二面的题不难,但是问的比较有深度,还是基础太差了
一面:
  1. IO多路复用
  1. 进程和线程

  2. 进程通信的方式

  3. 四次挥手过程

  4. ConcurrentHashMap

  5. 笔试题

    (1)32GB的文件,1GB内存,怎么实现排序

    (2)拓扑排序

二面:
栈实现队列

-- 正确性证明(实在不知道这个正确性是怎么证明)

-- 时间复杂度优化(优化后,但是不知道怎么计算)

-- 时间复杂度计算

--多线程环境下顺序保证

再贴一个优化后的代码吧
public class MyQueue {

    Deque<Integer> stack1;
    Deque<Integer> stack2;

    /**
     * Initialize your data structure here.
     */
    public MyQueue() {
        stack1 = new LinkedList<>();
        stack2 = new LinkedList<>();
    }

    /**
     * Push element x to the back of queue.
     */
    public void push(int x) {
        stack1.push(x);
    }

    /**
     * Removes the element from in front of queue and returns that element.
     */
    public synchronized int pop() {
        if(!stack2.isEmpty())
            return stack2.pop();
        while (!stack1.isEmpty())
            stack2.push(stack1.pop());
        return stack2.pop();
    }

    /**
     * Get the front element.
     */
    public synchronized int peek() {
        if(!stack2.isEmpty())
            return stack2.peek();
        while (!stack1.isEmpty())
            stack2.push(stack1.pop());
        return stack2.peek();
    }

    /**
     * Returns whether the queue is empty.
     */
    public boolean empty() {
        return stack1.isEmpty() && stack2.isEmpty();
    }

}


更多模拟面试

全部评论

(2) 回帖
加载中...
话题 回帖

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐