leetcood学习笔记-226- 翻转二叉树】的更多相关文章

题目描述; 第一次提交; class Solution: def isUnivalTree(self, root: TreeNode) -> bool: if root == None: return True if root.left!=None and root.left.val!=root.val: return False if root.right!=None and root.right.val != root.val: return False if self.isUnivalTr…
---恢复内容开始--- 题目描述: 方法一: class Solution(object): def isBalanced(self, root): """ :type root: TreeNode :rtype: bool """ if not root: return True : return False else: return self.isBalanced(root.left) and self.isBalanced(root.ri…
题目描述: 方法一:递归: class Solution: def isSymmetric(self, root: TreeNode) -> bool: if not root: return True def Tree(p, q): if not p and not q: return True if p and q and p.val == q.val : return Tree(p.left, q.right) and Tree(p.right, q.left) return False…
226. 翻转二叉树 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 备注: 这个问题是受到 Max Howell 的 原问题 启发的 : 谷歌:我们90%的工程师使用您编写的软件(Homebrew),但是您却无法在面试时在白板上写出翻转二叉树这道题,这太糟糕了. /** * Definition for a binary tree node. * public class TreeNode { *…
题目描述: 第一次提交: class Solution(object): def invertTree(self, root): """ :type root: TreeNode :rtype: TreeNode """ if not root: return None temp = root.left root.left = root.right root.right = temp# root.left,root.right = root.ri…
翻转一棵二叉树. 示例: 思想 递归 java版 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public TreeNode invertTree(TreeNode root) { if(root == nu…
题目描述: 翻转一颗二叉树 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 思路分析: 1)递归,不断交换左右子树,直到子树为空 public static TreeNode invertTree(TreeNode root) { if (root != null) { TreeNode tempNode = invertTree(root.left); root.left = invertTree(root.rig…
题目描述: 第一次提交: class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: j,x = 0,1 l = [] if matrix==[]: return [] m = len(matrix) n = len(matrix[0]) while x<=n*m: for i in range(j,n-j): l.append(matrix[j][i]) x += 1 for i in range(…
题目 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 本题同[剑指Offer]面试题27. 二叉树的镜像 思路一:递归 代码 时间复杂度:O(n) 空间复杂度:O(n) class Solution { public: TreeNode* invertTree(TreeNode* root) { if (root) { TreeNode *node = root->left; root->left…
python字符串与列表的相互转换   学习内容: 1.字符串转列表 2.列表转字符串 1. 字符串转列表 str1 = "hi hello world" print(str1.split(" "))输出:['hi', 'hello', 'world'] 2. 列表转字符串 l = ["hi","hello","world"] print(" ".join(l))输出:hi hello…