Open
Conversation
Ryotaro25
reviewed
Jul 31, 2025
| - https://github.com/goto-untrapped/Arai60/pull/54#discussion_r1780641914 | ||
| - 具体例の考え方について。私も複雑な例から考えてしまっていた。 | ||
| - コードが書けて正当性について他者に説明できる理解の精度がないといけませんね。 | ||
| - while で書くパターン。 |
There was a problem hiding this comment.
以前小田さんから「再帰とループの中間を念頭において、対応関係から相互に変換できるようにしておくといいでしょう。」とコメントをいただいたことがございます。リンク先にコードもございます🙇
Ryotaro25/leetcode_first60#50 (comment)
Owner
Author
There was a problem hiding this comment.
再帰とループの対応は考えてましたが中間というものは考えたことがありませんでした。
Python では書きにくそうですね。コメントありがとうございます。
Ryotaro25
reviewed
Jul 31, 2025
| return [None, None] | ||
|
|
||
| if root.val <= target: | ||
| smaller, greater = self.splitBST(root.right, target) |
There was a problem hiding this comment.
smarller_root greater_rootとする方が分かりやすいと感じました。
Fuminiton
reviewed
Jul 31, 2025
| node_in_greater_bst = node_in_greater_bst.left | ||
| node = node.left | ||
| node_in_greater_bst.left = None | ||
| return [smaller_bst_root.right, greater_bst_root.left] |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This Problem
776. Split BST
Given the root of a binary search tree (BST) and an integer target, split the tree into two subtrees where the first subtree has nodes that are all smaller or equal to the target value, while the second subtree has all nodes that are greater than the target value. It is not necessarily the case that the tree contains a node with the value target.
Additionally, most of the structure of the original tree should remain. Formally, for any child c with parent p in the original tree, if they are both in the same subtree after the split, then node c should still have the parent p.
Return an array of the two roots of the two subtrees in order.
Example 1:
Input: root = [4,2,6,1,3,5,7], target = 2
Output: [[2,1],[4,3,6,null,null,5,7]]
Example 2:
Input: root = [1], target = 1
Output: [[1],[]]
Constraints:
The number of nodes in the tree is in the range [1, 50].
0 <= Node.val, target <= 1000
Next Ploblem
3. Longest Substring Without Repeating Characters
言語: Python