mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
1. Add build script for Java.
2. Add height limitation for code blocks in extra.css. 3. Fix "节点" to "结点".
This commit is contained in:
@ -74,6 +74,7 @@ public class space_complexity {
|
||||
/* 平方阶(递归实现) */
|
||||
static int quadraticRecur(int n) {
|
||||
if (n <= 0) return 0;
|
||||
// 数组 nums 长度为 n, n-1, ..., 2, 1
|
||||
int[] nums = new int[n];
|
||||
System.out.println("递归 n = " + n + " 中的 nums 长度 = " + nums.length);
|
||||
return quadraticRecur(n - 1);
|
||||
|
||||
@ -9,11 +9,9 @@ package chapter_sorting;
|
||||
import java.util.*;
|
||||
|
||||
public class merge_sort {
|
||||
/**
|
||||
* 合并左子数组和右子数组
|
||||
* 左子数组区间 [left, mid]
|
||||
* 右子数组区间 [mid + 1, right]
|
||||
*/
|
||||
/* 合并左子数组和右子数组 */
|
||||
// 左子数组区间 [left, mid]
|
||||
// 右子数组区间 [mid + 1, right]
|
||||
static void merge(int[] nums, int left, int mid, int right) {
|
||||
// 初始化辅助数组
|
||||
int[] tmp = Arrays.copyOfRange(nums, left, right + 1);
|
||||
|
||||
@ -123,7 +123,7 @@ class QuickSortTailCall {
|
||||
}
|
||||
|
||||
/* 快速排序(尾递归优化) */
|
||||
static void quickSort(int[] nums, int left, int right) {
|
||||
public static void quickSort(int[] nums, int left, int right) {
|
||||
// 子数组长度为 1 时终止
|
||||
while (left < right) {
|
||||
// 哨兵划分操作
|
||||
|
||||
@ -10,7 +10,7 @@ import include.*;
|
||||
|
||||
/* AVL 树 */
|
||||
class AVLTree {
|
||||
TreeNode root; // 根节点
|
||||
TreeNode root; // 根结点
|
||||
|
||||
/* 获取结点高度 */
|
||||
public int height(TreeNode node) {
|
||||
@ -42,7 +42,7 @@ class AVLTree {
|
||||
// 更新结点高度
|
||||
updateHeight(node);
|
||||
updateHeight(child);
|
||||
// 返回旋转后子树的根节点
|
||||
// 返回旋转后子树的根结点
|
||||
return child;
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ class AVLTree {
|
||||
// 更新结点高度
|
||||
updateHeight(node);
|
||||
updateHeight(child);
|
||||
// 返回旋转后子树的根节点
|
||||
// 返回旋转后子树的根结点
|
||||
return child;
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ class AVLTree {
|
||||
updateHeight(node); // 更新结点高度
|
||||
/* 2. 执行旋转操作,使该子树重新恢复平衡 */
|
||||
node = rotate(node);
|
||||
// 返回子树的根节点
|
||||
// 返回子树的根结点
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ class AVLTree {
|
||||
updateHeight(node); // 更新结点高度
|
||||
/* 2. 执行旋转操作,使该子树重新恢复平衡 */
|
||||
node = rotate(node);
|
||||
// 返回子树的根节点
|
||||
// 返回子树的根结点
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ public class binary_tree_bfs {
|
||||
List<Integer> list = new ArrayList<>();
|
||||
while (!queue.isEmpty()) {
|
||||
TreeNode node = queue.poll(); // 队列出队
|
||||
list.add(node.val); // 保存结点
|
||||
list.add(node.val); // 保存结点值
|
||||
if (node.left != null)
|
||||
queue.offer(node.left); // 左子结点入队
|
||||
if (node.right != null)
|
||||
|
||||
Reference in New Issue
Block a user