Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes ...
分类:
其他好文 时间:
2017-10-07 14:56:14
阅读次数:
177
作为一个数据结构学傻,终于要开始入这个坑了...... 之前一直不写有关数据结构的东西,是因为不会画那种很高端的图,所以一直不写,现在看来似乎没有办法避免了…… LCA,全称Least Common Ancestor,即最近公共祖先,顾名思义,LCA(u,v)就是u和v的所有共同祖先中深度最小的,很 ...
分类:
其他好文 时间:
2017-10-04 15:16:06
阅读次数:
176
srand函数是随机数发生器的初始化函数。 原型: void srand(unsigned seed); 用法:它需要提供一个种子,这个种子会对应一个随机数,如果使用相同的种子后面的rand()函数会出现一样的随机数。如: srand(1); 直接使用 1 来初始化种子。不过为了防止随机数每次重复, ...
分类:
其他好文 时间:
2017-09-28 18:02:23
阅读次数:
200
LCA问题第一弹 上篇文章讲到 区间最值 RMQ 问题,今天,我们来研究一下 LCA 问题。 LCA( Least Common Ancestor)问题:中文名为“ 最近公共祖先”问题。LCA问题定义是这样的:在一个树形结构中,求解两个子节点的公共祖先中离根节点最远的那个祖先节点,换言之,分别从两个 ...
分类:
其他好文 时间:
2017-09-17 01:31:53
阅读次数:
249
来源:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree Given a binary tree, find the lowest common ancestor (LCA) of two given nodes ...
分类:
其他好文 时间:
2017-09-12 21:58:45
阅读次数:
187
面向对象程序设计中最重要的一个概念是继承。继承允许我们依据另一个类来定义一个类,这使得创建和维护一个应用程序变得更容易。这样做,也达到了重用代码功能和提高执行时间的效果。 当创建一个类时,您不需要重新编写新的数据成员和成员函数,只需指定新建的类继承了一个已有的类的成员即可。这个已有的类称为基类,新建 ...
分类:
编程语言 时间:
2017-09-12 17:44:24
阅读次数:
162
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */... ...
分类:
其他好文 时间:
2017-08-31 16:13:14
阅读次数:
98
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any p... ...
分类:
其他好文 时间:
2017-08-30 11:02:30
阅读次数:
138
$("span,#two").css("background","#bbffaa"); 改变所有的<span>元素和id为two的元素的背景色; $("ancestor descendant") 选取ancestor元素里的所有descendant(后代)元素,包含子元素、孙子元素等; $("par ...
分类:
Web程序 时间:
2017-08-29 21:39:00
阅读次数:
187
【062-Unique Paths(唯一路径)】 【LeetCode-面试算法经典-Java实现】【全部题目文件夹索引】 原题 A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagr ...
分类:
编程语言 时间:
2017-08-20 15:50:31
阅读次数:
146