Last active
March 14, 2019 08:50
-
-
Save HoweChen/9fa623f4cdaf2259b8c96d1b4ab5f23d to your computer and use it in GitHub Desktop.
[inorderBST]using yield and yiled from #Python #Algorithm
This file contains 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
class Solution: | |
def increasingBST(self, root): | |
def inorder(node): | |
if node: | |
# 这里用了yield 和 yield from | |
# yield from 作为递归 | |
# yield 返回值 | |
# 这是一个左中右的 inorder 遍历 | |
# 返回一个 generator | |
yield from inorder(node.left) | |
yield node.val | |
yield from inorder(node.right) | |
ans = cur = TreeNode(None) | |
for v in inorder(root): | |
cur.right = TreeNode(v) | |
cur = cur.right | |
return ans.right |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment