binghe2727 / Key-Algorithms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Key-Algorithms

Algorithms 4th edition重点算法,对于刷题,复习,准备面试都有很大帮助。

第1章 基础

1.基础算法

第2章 排序

2.排序算法

第3章 查找

3.查找算法

第4章 图

4.图算法

第5章 字符串

5.字符串算法

[第6章 背景]

6.其余背景算法

新增 无注释 No Comment 版本

无注释版本

无注释版本 可以用来复习。复习时,自己主动给关键部分写注释,再对照原来的注释,看看是否真正理解。

去掉注释使用的批量去注释小软件:

批量去注释-Java

举一个刷题的小例子:

leetcode 104题:找到二叉树最大深度

如果记得 3.3binary search tree里面关于height的code,就可以瞬间写出bug free的solution了。

以下是3.3binary search tree里面关于height的code:

/**
* Returns the height of the BST (for debugging).
*
* @return the height of the BST (a 1-node tree has height 0)
*/
public int height() {
    return height(root);
}
private int height(Node x) {
    if (x == null) return -1;
    return 1 + Math.max(height(x.left), height(x.right));
}



//以下是104题的解法:



/**
* Definition for a binary tree node.
* public class TreeNode {
*     int val;
*     TreeNode left;
*     TreeNode right;
*     TreeNode(int x) { val = x; }
* }
*/
public class Solution {
    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        return 1 + Math.max(root.left, root.right);
    }
}

About


Languages

Language:Java 100.0%