226. Invert Binary Tree | Java最短代码实现
来源:互联网 发布:上海证券交易软件下载 编辑:程序博客网 时间:2024/05/20 13:39
原题链接:226. Invert Binary Tree
欢迎优化!
【思路】
对于每个节点,交换左右子树,然后递归左右子树,这样就实现了数的反转:
public TreeNode invertTree(TreeNode root) { if (root == null) return root; TreeNode tmp = root.left; root.left = root.right; root.right = tmp; invertTree(root.left); invertTree(root.right); return root; }68 / 68 test cases passed. Runtime: 0 ms Your runtime beats 21.92% of javasubmissions.
欢迎优化!
1 0
- 226. Invert Binary Tree | Java最短代码实现
- Flatten Binary Tree to Linked List | Java最短代码实现
- 235. Lowest Common Ancestor of a Binary Search Tree | Java最短代码实现
- Lowest Common Ancestor of a Binary Tree | Java最短代码实现
- 105. Construct Binary Tree from Preorder and Inorder Traversal | Java最短代码实现
- 331. Verify Preorder Serialization of a Binary Tree | Java最短代码实现
- leetcode-226. Invert Binary Tree c++ java
- 226.Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- Mac搭建web后端开发环境:jdk +Eclipse EE + SVN + Tomcat + MySql + mysqlWorkbench
- HDU_ACM_A+B for Input-Output Practice (IV)
- C#时间DateTime包含星期存入数据库错误
- the summary of greedy strategy
- Theano下用CNN(卷积神经网络)做车牌中文字符OCR
- 226. Invert Binary Tree | Java最短代码实现
- 机器学习:贝叶斯_1:贝叶斯估计
- 跑 NeuralStyle (使用CNN进行的画风迁移实验)
- 逆序整数二进制
- Qt使用QGraphicsView实现滑动窗体效果 .
- Eclipse 常用快捷键
- HDU_ACM_A+B for Input-Output Practice (V)
- 详解Java中的checked异常和unchecked异常
- dispatch_once让代码只执行一次