上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 44 下一页
摘要: 问题: 计算给定完全二叉树的节点个数。 Example: Input: 1 / \ 2 3 / \ / 4 5 6 Output: 6 解法:Complete Binary Tree(完全二叉树) 首先明确以下定义: (了解即可)Full Binary Tree 国际定义的 满二叉树 定义:A bi 阅读全文
posted @ 2020-09-30 08:03 habibah_chang 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 问题: 给出一颗二叉树,两个节点p和q,求出这两节点的最近公共父节点(LCA)。 Example 1: Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1 Output: 3 Explanation: The LCA of nodes 阅读全文
posted @ 2020-09-28 16:19 habibah_chang 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 问题: 实现下面两个转换: TreeNode* -> string string -> TreeNode* Example 1: Input: root = [1,2,3,null,null,4,5] Output: [1,2,3,null,null,4,5] Example 2: Input: r 阅读全文
posted @ 2020-09-26 18:30 habibah_chang 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 654. Maximum Binary Tree 问题: 用给定的数组,构成最大二叉树。 从数组中找到最大值,作为root,其index以左,作为左子树。index以右,作为右子树。 Example 1: Input: [3,2,1,6,0,5] Output: return the tree ro 阅读全文
posted @ 2020-09-26 14:02 habibah_chang 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 问题: 拉平二叉树 -> 只有right分支的链表。 For example, given the following tree: 1 / \ 2 5 / \ \ 3 4 6 The flattened tree should look like: 1 \ 2 \ 3 \ 4 \ 5 \ 6 解法: 阅读全文
posted @ 2020-09-22 11:26 habibah_chang 阅读(124) 评论(0) 推荐(0) 编辑
摘要: 二叉树 Binary Tree -【两棵树 对比】 问题: 给定 层序遍历的数组 表示二叉树。 100. 判断两棵二叉树是否相同。 Example 1: Input: 1 1 / \ / \ 2 3 2 3 [1,2,3], [1,2,3] Output: true Example 2: Input 阅读全文
posted @ 2020-09-19 15:32 habibah_chang 阅读(331) 评论(0) 推荐(0) 编辑
摘要: 二叉树 Binary Tree -【一棵树 内部求最值or求和】 问题: 给定 层序遍历的数组 表示二叉树。 ⚠️ 注意:leaf节点:既无左孩子,又无右孩子 104:求二叉树的最深层数 Example: Given binary tree [3,9,20,null,null,15,7], 3 / 阅读全文
posted @ 2020-09-19 12:11 habibah_chang 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 参考:经典动态规划:打家劫舍系列问题 问题: base题目: 给定一组数列,代表一排住宅,各自能偷出的钱数。 不能偷取相邻的两家。求能偷出的最大钱数。 I base题目 Example 1: Input: nums = [1,2,3,1] Output: 4 Explanation: Rob hou 阅读全文
posted @ 2020-09-18 10:48 habibah_chang 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 参考:团灭股票问题 base问题:188. Best Time to Buy and Sell Stock IV 问题: 股票问题: 给出一组一支股票每日的价格数组。prices[] 每一天的操作可以为:买buy,卖sell,不操作rest 在第二次buy之前,需要离上一次sell隔一天冷静期,求可 阅读全文
posted @ 2020-09-17 17:07 habibah_chang 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 参考:团灭股票问题 问题: 股票问题: 给出一组一支股票每日的价格数组。prices[] 每一天的操作可以为:买buy,卖sell,不操作rest 一次交易从buy开始,若限制在K次交易以内,求可获得的最大收益是多少。 解法:DP(动态规划) 1.确定【状态】: 当前的天数:第 i 天 当前经过的交 阅读全文
posted @ 2020-09-13 16:27 habibah_chang 阅读(100) 评论(0) 推荐(0) 编辑
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 44 下一页