稳如老狗,才能赢
Talk is cheap, show me the code.
提示:身体和思想要保持一致,想法不是事实
JVM类加载机制是什么样子的呢?
JVM中哪些地方可能会内存溢出?什么场景会导致内存溢出呢?
如果新生代和老年代的所有内存只有100M,但是定义了一个200M的对象,会内存溢出吗?
如果redis集群中的主服务器突然宕机了,那么怎么从从服务器中选出一个主节点呢?选举机制是什么样子的?
redis数据类型?分别使用场景是什么?
redis中的 z set 结构有过了解吗?使用场景是什么?
如果我在linux里面想要查看一个日志文件,大致会用到什么指令?
MySQL的存储引擎介绍一下?
为什么MySQL使用B+树索引结构,不采用二叉树、红黑树或者B树呢?
剑指 Offer 30. 包含min函数的栈;
思路:
代码如下:
class MinStack {Stack stack;Stack help;/** initialize your data structure here. */public MinStack() {// initializationstack = new Stack<>();help = new Stack<>();}public void push(int x) {stack.push(x);if(help.isEmpty() || help.peek() >= x){help.push(x);}}public void pop() {if(stack.pop().equals(help.peek())){help.pop();}}public int top() {return stack.peek();}public int min() {return help.peek();}
}/*** Your MinStack object will be instantiated and called as such:* MinStack obj = new MinStack();* obj.push(x);* obj.pop();* int param_3 = obj.top();* int param_4 = obj.min();*/
思路:
代码如下:
class Solution {// 判断第二个数组是否为第一个数组弹出栈的顺序public boolean validateStackSequences(int[] pushed, int[] popped) {Stack stack = new Stack<>();int j = 0;for(int push : pushed){stack.push(push);while(!stack.isEmpty() && stack.peek() == popped[j]){stack.pop();j++;}}return stack.isEmpty();}
}
剑指 Offer 37. 序列化二叉树;
思路:
代码如下:
/*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val = x; }* }*/
public class Codec {// Encodes a tree to a single string.public String serialize(TreeNode root) {if(root == null){return "[]";}StringBuilder sb = new StringBuilder("[");Queue queue = new LinkedList<>();queue.add(root);while(!queue.isEmpty()){TreeNode head = queue.poll();if(head != null){sb.append(head.val + ",");queue.add(head.left);queue.add(head.right);}else{sb.append("null,");}}sb.deleteCharAt(sb.length() - 1);sb.append("]");return sb.toString();}// Decodes your encoded data to tree.public TreeNode deserialize(String data) {if(data.equals("[]")){return null;}String[] array = data.substring(1, data.length() - 1).split(",");Queue queue = new LinkedList<>();TreeNode root = new TreeNode(Integer.parseInt(array[0]));queue.add(root);int i = 1;while(!queue.isEmpty()){TreeNode head = queue.poll();if(!array[i].equals("null")){head.left = new TreeNode(Integer.parseInt(array[i]));queue.add(head.left);}i++;if(!array[i].equals("null")){head.right = new TreeNode(Integer.parseInt(array[i]));queue.add(head.right);} i++;}return root;}
}// Your Codec object will be instantiated and called as such:
// Codec codec = new Codec();
// codec.deserialize(codec.serialize(root));
每天都要学习一点点