public class MaxDiv {
public static void main(String[] args) {
// 1. 给定一个整数N,寻找能够整除N的最大整数
System.out.println(Maxint(6));
}
public static int Maxint(int n) {
int m=n/2;
while(m>0) {
if (n%m==0) {
return m;
}
m--;
}
return -1;
}
}
2.已知前序中序 求后序
import java.util.HashMap;
public class OderTree {
static HashMap<Integer, Integer> dic = new HashMap<>();
public static int[] po;
public static void main(String[] args) {
// TODO 自动生成的方法存根
int []pre= {2,3,4,5,6,8,7};
int []inf= {4,3,5,2,8,6,7};
TreeNode tNode=buildTree(pre, inf);
tNode.postOder();
}
static class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
}
//后序
public void postOder(){
if (this.left!=null)
this.left.postOder();
if (this.right!=null)
this.right.postOder();
System.out.println(this);
}
@Override
public String toString() {
return "TreeNode [val=" + val + "]";
}
}
public static TreeNode buildTree(int[] preorder, int[] inorder) {
po = preord