动态规划总结
动态规划算法的设计主要有以下4个步骤
(1) 描述最优解的结构
(2) 递归定义最优解的值
(3) 按自底向上的方式计算最优解的值
(4) 由计算出的结果构造一个最优解
其实最核心的步骤是 定义一个描述最优解的递归公式 (状态转移方程)
stay hungry stay foolish
sudo apt-get install git
需要在github创建一个名称为username.github.io的项目
同时配置ssh,可以连接github,详情看
https://help.github.com/articles/connecting-to-github-with-ssh/
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of itself).”
_______6______
/ \
___2__ ___8__
/ \ / \
0 _4 7 9
/ \
3 5
For example, the lowest common ancestor (LCA) of nodes 2 and 8 is 6. Another example is LCA of nodes 2 and 4 is 2, since a node can be a descendant of itself according to the LCA definition.