面试总结2
1、MySQL查询方式:https://www.cnblogs.com/bypp/p/7755307.html
2、hhvm
3、如何判断一个二叉树是否为二叉搜索树
中序遍历:
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ import java.util.*; public class Solution { public boolean isValidBST(TreeNode root) { ArrayList<TreeNode> list = new ArrayList<TreeNode>(); if(root ==null){ return true; } inorder(root,list); for(int i=0;i<list.size()-1;i++){ if(list.get(i).val>=list.get(i+1).val){ return false; } } return true; } public static void inorder(TreeNode root,ArrayList<TreeNode> list){ if(root!=null){ inorder(root.left,list); list.add(root); inorder(root.right,list); } } }
4、二叉树层次遍历
public void levelIterator(TreeNode n){ Queue<TreeNode> queue = new LinkedList<TreeNode>(); queue.offer(n); while (!queue.isEmpty()) { TreeNode t = queue.poll(); if (t !=null) { System.out.println("key:"+t.key+"--name:"+t.data); } if (t.leftChild !=null) { queue.offer(t.leftChild); } if (t.rightChild !=null) { queue.offer(t.rightChild); } } }
5、二叉树非递归后续遍历
//前序遍历的非递归实现
public void nonRecPreOrder(TreeNode p){
Stack<TreeNode> stack=new Stack<TreeNode>();
TreeNode node=p;
while(node!=null||stack.size()>0){
while(node!=null){
System.out.println("key:"+node.key+"--name:"+node.data);;
stack.push(node);
node=node.leftChild;
}
if(stack.size()>0){
node=stack.pop();
node=node.rightChild;
}
}
}
//中序遍历的非递归实现
public void nonRecInOrder(TreeNode p){
Stack<TreeNode> stack =new Stack<TreeNode>();
TreeNode node =p;
while(node!=null||stack.size()>0){
//存在左子树
while(node!=null){
stack.push(node);
node=node.leftChild;
}
//栈非空
if(stack.size()>0){
node=stack.pop();
System.out.println("key:"+node.key+"--name:"+node.data);
node=node.rightChild;
}
}
}
//后序遍历的非递归实现
public void noRecPostOrder(TreeNode p){
Stack<TreeNode> stack=new Stack<TreeNode>();
TreeNode node =p;
while(p!=null){
//左子树入栈
for(;p.leftChild!=null;p=p.leftChild){
stack.push(p);
}
//当前结点无右子树或右子树已经输出
while(p!=null&&(p.rightChild==null||p.rightChild==node)){
System.out.println("key:"+p.key+"--name:"+p.data);;
//纪录上一个已输出结点
node =p;
if(stack.empty())
return;
p=stack.pop();
}
//处理右子树
stack.push(p);
p=p.rightChild;
}
}
6、php-fpm的运行方式
7、Innodb和missame 所有有什么区别