- Notifications
You must be signed in to change notification settings - Fork0
add new solution#2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
17 changes: 15 additions & 2 deletions...leetcode/editor/cn/doc/[124]二叉树中的最大路径和.py → script/[124]二叉树中的最大路径和.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletionsscript/[654]最大二叉树.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# 给定一个不重复的整数数组 nums 。 最大二叉树 可以用下面的算法从 nums 递归地构建: | ||
# | ||
# | ||
# 创建一个根节点,其值为 nums 中的最大值。 | ||
# 递归地在最大值 左边 的 子数组前缀上 构建左子树。 | ||
# 递归地在最大值 右边 的 子数组后缀上 构建右子树。 | ||
# | ||
# | ||
# 返回 nums 构建的 最大二叉树 。 | ||
# | ||
# | ||
# | ||
# 示例 1: | ||
# | ||
# | ||
# 输入:nums = [3,2,1,6,0,5] | ||
# 输出:[6,3,5,null,2,0,null,null,1] | ||
# 解释:递归调用如下所示: | ||
# - [3,2,1,6,0,5] 中的最大值是 6 ,左边部分是 [3,2,1] ,右边部分是 [0,5] 。 | ||
# - [3,2,1] 中的最大值是 3 ,左边部分是 [] ,右边部分是 [2,1] 。 | ||
# - 空数组,无子节点。 | ||
# - [2,1] 中的最大值是 2 ,左边部分是 [] ,右边部分是 [1] 。 | ||
# - 空数组,无子节点。 | ||
# - 只有一个元素,所以子节点是一个值为 1 的节点。 | ||
# - [0,5] 中的最大值是 5 ,左边部分是 [0] ,右边部分是 [] 。 | ||
# - 只有一个元素,所以子节点是一个值为 0 的节点。 | ||
# - 空数组,无子节点。 | ||
# | ||
# | ||
# 示例 2: | ||
# | ||
# | ||
# 输入:nums = [3,2,1] | ||
# 输出:[3,null,2,null,1] | ||
# | ||
# | ||
# | ||
# | ||
# 提示: | ||
# | ||
# | ||
# 1 <= nums.length <= 1000 | ||
# 0 <= nums[i] <= 1000 | ||
# nums 中的所有整数 互不相同 | ||
# | ||
# Related Topics 栈 树 数组 分治 二叉树 单调栈 | ||
# 👍 460 👎 0 | ||
# leetcode submit region begin(Prohibit modification and deletion) | ||
# Definition for a binary tree node. | ||
# class TreeNode: | ||
# def __init__(self, val=0, left=None, right=None): | ||
# self.val = val | ||
# self.left = left | ||
# self.right = right | ||
classSolution: | ||
defconstructMaximumBinaryTree(self,nums:List[int])->TreeNode: | ||
defdfs(start,end): | ||
ifstart>end: | ||
returnNone | ||
ifstart==end: | ||
returnTreeNode(nums[start]) | ||
maxval=max(nums[start:(end+1)]) | ||
pos=nums.index(maxval) | ||
root=TreeNode(maxval) | ||
root.left=dfs(start,pos-1) | ||
root.right=dfs(pos+1,end) | ||
returnroot | ||
returndfs(0,len(nums)-1) | ||
# leetcode submit region end(Prohibit modification and deletion) |
52 changes: 0 additions & 52 deletionsscript/leetcode/editor/cn/doc/[110]平衡二叉树.py
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
86 changes: 0 additions & 86 deletionsscript/leetcode/editor/cn/doc/[173]二叉搜索树迭代器.py
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
65 changes: 65 additions & 0 deletions树总结.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.