Gordon Lee

Results 5 issues of Gordon Lee

``` def populate_word_blacklist(word_index): blacklisted_words = set() blacklisted_words |= set(global_config.predefined_word_index.values()) if global_config.filter_sentiment_words: blacklisted_words |= lexicon_helper.get_sentiment_words() if global_config.filter_stopwords: blacklisted_words |= lexicon_helper.get_stopwords() ``` 1. The output of `global_config.predefined_word_index.values()` are indices of some words,...

[543. 二叉树的直径](https://leetcode.cn/problems/diameter-of-binary-tree/) - 给定一棵二叉树,你需要计算它的直径长度。一棵二叉树的直径长度是任意两个结点路径长度中的最大值。这条路径可能穿过也可能不穿过根结点。**注意:**两结点之间的路径长度是以它们之间边的数目表示。 ```C++ class Solution { public: int res = INT_MIN; int dfs(TreeNode *root){ if(!root) return 0; int left_val = dfs(root->left); int right_val = dfs(root->right); int cur =...

二叉树
递归

* [101. 对称二叉树](https://leetcode-cn.com/problems/symmetric-tree/) - 给你一个二叉树的根节点 `root`, 检查它是否轴对称。 - 递归遍历+问题分解+分类讨论 - 子结构: 两棵小树p和q, 同步遍历两棵树 - 终止条件:p和q其中一方为空 或者 p 和 q不相等 return false - 否则: 递归判定: (左子树,右子树) (右子树,左子树) ```C++ class Solution {...

二叉树
递归

* [100. 相同的树](https://leetcode-cn.com/problems/same-tree/) * 给你两棵二叉树的根节点 `p` 和 `q` ,编写一个函数来检验这两棵树是否相同。如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。 * 递归定义法:按照定义法来做 * 定义: 如果两棵树相等则左子树和左子树相同, 右子树和右子树相同, 且根的值相同 * 分类讨论终止: pq其中一个为空, 直接返回false; pq均为空, 则返回true ```c++ class Solution { public: //递归定义+分类讨论 //定义: 如果两棵树相等则左子树和左子树相同,...

二叉树
递归

[110. 平衡二叉树](https://leetcode.cn/problems/balanced-binary-tree/) * 给定一个二叉树,判断它是否是高度平衡的二叉树。本题中,一棵高度平衡二叉树定义为:一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1 。 * 递归定义法:按照定义法来做 * 问题分解: 求高度, 然后求是否平衡 * 递归定义: 一颗高度平衡二叉树的左子树是平衡的;右子树是平衡的; 再判断这个子结构是否是平衡的 ```C++ class Solution { public: //问题分解: 求高度, 然后求是否平衡 //递归定义: 一颗高度平衡二叉树的左子树是平衡的;右子树是平衡的; 再判断这个子结构是否是平衡的 int getMaxDepth(TreeNode*...

二叉树
递归