终于自己做出来一道。。。 递归思路1 参考递归求解最大深度,构造新函数,将节点当前路径和当作额外参数传入 这个题比较特殊的地方在于,必须是叶子节点所在的路径才有效,因此在return true的条件中加入了left right均为`nullptr 返回时使用||不影响某个分支上的正确结果 class ...
分类:
其他好文 时间:
2020-07-16 21:13:09
阅读次数:
43
Find Right Interval (M) 题目 Given a set of intervals, for each of the interval i, check if there exists an interval j whose start point is bigger than ...
分类:
其他好文 时间:
2020-07-16 12:10:10
阅读次数:
63
扔硬币 题解: 1.如果\(\left ( m+k\right )> n\),那么就很明显答案为0; 2.根据条件概率:则题目就是求,在至少有\(m\)枚硬币是反面的情况下,恰好有\(k\)枚硬币是正面的概率。那么就可以设\(A\)为至少有\(m\)枚硬币是反面,\(B\)为恰好有\(k\)枚硬币是 ...
分类:
其他好文 时间:
2020-07-16 00:23:21
阅读次数:
105
Given an array, rotate the array to the right by k steps, where k is non-negative. Follow up: Try to come up as many solutions as you can, there are a ...
分类:
其他好文 时间:
2020-07-16 00:20:51
阅读次数:
49
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { ...
分类:
其他好文 时间:
2020-07-16 00:01:06
阅读次数:
61
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ ...
分类:
其他好文 时间:
2020-07-15 23:40:01
阅读次数:
70
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ ...
分类:
其他好文 时间:
2020-07-15 23:31:48
阅读次数:
66
public boolean isBalanced(TreeNode root) { if (root == null) { return true; } int diff = getDepth(root.left) - getDepth(root.right); diff = diff > 0 ? ...
分类:
其他好文 时间:
2020-07-15 22:51:05
阅读次数:
53
输出二叉树中的叶子结点 void PreOrderPrintLeaves( BinTree BT ) { if( BT ) { if ( !BT-Left && !BT->Right )// 在二叉树的遍历算法中增加检测结点的“左右子树是否都为空”。 printf(“%d”, BT->Data ); ...
分类:
其他好文 时间:
2020-07-15 15:28:16
阅读次数:
72
题目给定一个完美二叉树,其所有叶子节点都在同一层,每个父节点都有两个子节点。二叉树定义如下: struct Node {int val;Node *left;Node *right;Node *next;}填充它的每个 next 指针,让这个指针指向其下一个右侧节点。如果找不到下一个右侧节点,则将 ...
分类:
其他好文 时间:
2020-07-15 01:06:48
阅读次数:
77