题目:
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest p...
分类:
编程语言 时间:
2015-07-12 11:20:56
阅读次数:
206
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ...
分类:
其他好文 时间:
2015-07-12 11:07:12
阅读次数:
170
题目很好理解,即求一棵二叉树中两个节点的公共祖先。
我的解题思路是使用DFS,求出从根节点到两个待查节点各自的路径,然后从头开始比较两个路径,最后一个相等的节点即为公共祖先节点。完整代码如下。
class Solution {
public:
//DFS代码
void findNode(TreeNode* root, TreeNode* toFind, vector &curPath...
分类:
其他好文 时间:
2015-07-12 09:39:01
阅读次数:
122
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ...
分类:
其他好文 时间:
2015-07-12 06:58:48
阅读次数:
88
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...
分类:
其他好文 时间:
2015-07-11 22:56:23
阅读次数:
386
Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.Ac...
分类:
其他好文 时间:
2015-07-11 18:21:07
阅读次数:
121
Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.Ac...
分类:
其他好文 时间:
2015-07-11 18:03:46
阅读次数:
137
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
betw...
分类:
其他好文 时间:
2015-07-11 16:51:07
阅读次数:
126
https://leetcode.com/submissions/detail/32662938/Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST...
分类:
其他好文 时间:
2015-07-11 16:19:19
阅读次数:
98
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/Given a binary search tree (BST), find the lowest common ancestor (LCA) o...
分类:
其他好文 时间:
2015-07-11 16:18:22
阅读次数:
127