226.翻转二叉树
翻轉(zhuǎn)一棵二叉樹。
示例:
輸入:
4/ \2 7/ \ / \ 1 3 6 9輸出:
4/ \7 2/ \ / \ 9 6 3 1 class Solution:def invertTree(self, root: TreeNode) -> TreeNode:if not root:return rootroot.left,root.right = self.invertTree(root.right),self.invertTree(root.left)return root總結(jié)
- 上一篇: python返回列表中出现次数最多的数
- 下一篇: [leetcode]剑指offer32-