摘要:
已知BST的前序遍历,还原BST arr数组:前序遍历 list:排序后的 arr 数组【BST的 中序遍历】 public static TreeNode getRoot(int[] arr, List<Integer> list){ int index = -1; for (int i = 0; 阅读全文
摘要:
给定二叉树的前序遍历,遍历是否是 BST public static boolean isValid(int[] arr, int start, int end, int min, int max){ if (start > end){ // start > end:当前子树为空,返回 true,因 阅读全文
摘要:
互质数判断【空杯心态】 1 和任何其它都是互质数 相邻2个一定互质 2个不同的质数一定互质 欧几里德算法 通过递归计算两个数的最大公约数(GCD) 如果最大公约数为1,则说明两个数互质。 public static int gcd(int a, int b){ if (a == 0){ return 阅读全文