Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

qddoctor/Key-Algorithms

Repository files navigation

Key-Algorithms

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

第1章 基础

1.基础算法

第2章 排序

2.排序算法

第3章 查找

3.查找算法

第4章 图

4.图算法

第5章 字符串

5.字符串算法

[第6章 背景]

6.其余背景算法

举一个刷题的小例子:

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

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%

AltStyle によって変換されたページ (->オリジナル) /