惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
D
Docker
罗磊的独立博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog

Go Further

【教程】manim动画制作工具 【直观算法】二叉搜索树算法总结 【直观算法】二叉树遍历算法总结 【直观算法】Egg Puzzle 鸡蛋难题 博客文章总目录 TensorSpace 一个3D神经网络可视化框架 【直观详解】通俗易懂了解什么是黎曼猜想 支持币与去中心化商业模式 那些值得一看的TED演讲附全文文稿笔记 【区块链】共识算法与如何解决拜占庭将军问题 【直观详解】让你永远忘不了的傅里叶变换解析 【直观详解】泰勒级数 微信跳一跳解题报告 Dota2-A帐效果 深入浅出看懂AlphaGo Zero/AlphaGo元 【直观详解】线性代数中的转置正交正规正定 程序员技能图谱 【直观详解】线性代数的本质 【直观详解】什么是PCA、SVD 【直观详解】什么是正则化 Pandas-Wiki 【区块链】比特币与金融、ICO和监管 【区块链】现代区块链与新技术 【区块链】一文看懂区块链:一步一步发明比特币 【直观详解】拉格朗日乘法和KKT条件 【直观详解】支持向量机SVM Dota2伤害类型详解 【直观详解】机器学习分类器性能指标详解 【直观详解】信息熵、交叉熵和相对熵 Dota2机制总结
LeetcodeNote
2017-07-01 · via Go Further

LeetcodeNote

算法培训课程基本模型汇总笔记

线

基本模型

数学归纳法

基本模板

  • Draw/Equation -> Tree shape
  • Define TreeNode
    • 本点信息必然是辅助变量,计入TreeNode
    • 孩子信息决定TreeNode的形状
    • 任何第一次走的节点,如果不能走,一定要画出来打一把叉
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Public int func(T[] array, V tartget ){
int pos = -1;
int start = 0;
int end array.length - 1;
while ( start <= end ){
int mid = start + (end - start)/2;
if ( f(a[mid]) <= target ){
pos = mid;
start = mid + 1;
} else {
end = mid - 1;
}
}
return pos;
}

Bottom up - Recursion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public <T_P> func(T_v_1, v1 …){
checkhastreeNode();
return helper(root(T_v_1, v_1, …))
}

private <T_P> helper(T_v_1, v1, …){
resultchildfirst = helper(childFirst);

resultchildlast = helper(childLast);

-> result by childs


return result;
}

DFS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class DFSTree {
public Type_R func(T_1, e1, T_2, e2){
checkrootexists();

TreeNode[] array = new TreeNode[TREE_HEIGHT];

Stack<TreeNode> stack = Stack<>();
stack.push(root);
while (!stack.Empty()){
TreeNode curNode = stack.pop();

Operation at node;

stack.push(childLast);

stack.push(childFirst);
}

return result;
}

private class TreeNode{
T_V_1 field_1;

T_V_q field_q;

int _height;
}

BFS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class BFS {
public TypeR func(T_1 v_1, T_p, v_p) {
checkexistroot();

Queue<TreeNode> queue = new LinkedList<>();
queue.add(root);

while ( !queue.isEmpty() ){

int size = queue.size();
for ( int I = 0; I < size; i++ ){
TreeNode node = queue.remove();

op at node;

queue.add(childFirst);

queue.add(childLast);
}

update var_l,…,var_k for next level
}

return result;

}

private class TreeNode{
T_1 field_1;

}
}

基本模板