手撕代码:镜像二叉树
import java.util.Scanner;
class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
TreeNode(int val){
this.val = val;
}
}
class Solution{
public TreeNode reverse(TreeNode root) {
if (root == null) {
return null;
}
TreeNode tem = root.left;
root.left = root.right;
root.right = tem;
reverse(root.left);
reverse(root.right);
return root;
}
}
class Pri{
public TreeNode printall (TreeNode root) {
if (root == null) {
return null;
}
System.out.println(root.val);
printall(root.left);
printall(root.right);
return root;
}
}
public class Main {
public static void main(String[] args) {
//Scanner in = new Scanner(System.in);
//int a = in.nextInt();
//System.out.println(a);
TreeNode root = new TreeNode(4);
TreeNode root1 = new TreeNode(2);
TreeNode root2 = new TreeNode(7);
TreeNode root3 = new TreeNode(1);
TreeNode root4 = new TreeNode(3);
TreeNode root5 = new TreeNode(6);
TreeNode root6 = new TreeNode(9);
root.left = root1;
root.right = root2;
root1.left = root3;
root1.right = root4;
root2.left = root5;
root2.right = root6;
Solution s = new Solution();
s.reverse(root);
Pri p = new Pri();
p.printall(root);
}
}
问的都是java的知识:
equal如何重写,会怎么等?
static、final、this、super的区别
ArrayList 和 LinkedList的区别
说一说HashMap
说一说String、StringBuffer、StringBuilder的区别
说一说abstract和interferce的区别
说一说TCP/UDP五层模型???我就知道七层...被面试官嘲笑了???
(应用层、传输层、网络层、数据链路层、物理层)
说一说七层网络每一层都是干嘛的?
说一说JVM
说一说线程的实现方式
说一说垃圾回收机制
以后要多背java试题!!!