Lintcode 175 Invert Binary Tree
2024-10-15 12:02:07
I did it in a recursive way. There is another iterative way to do it. I will come back at it later.
/**
* Definition of TreeNode:
* public class TreeNode {
* public int val;
* public TreeNode left, right;
* public TreeNode(int val) {
* this.val = val;
* this.left = this.right = null;
* }
* }
*/
public class Solution {
/**
* @param root: a TreeNode, the root of the binary tree
* @return: nothing
*/ // method 1: recursion
// 注意交换的是node,不是int value
public void invertBinaryTree(TreeNode root) {
if (root == null)
return; TreeNode temp = root.left;
root.left = root.right;
root.right = temp; invertBinaryTree(root.left);
invertBinaryTree(root.right);
}
}
最新文章
- C# 之 DataReader 和 DataSet 的区别
- CodeForces 455D 分块
- iOS---初识Swift(一)
- MVC, MVP, MVVM比较以及区别
- archlinux更新错误
- C++中关于cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- 1015: [JSOI2008]星球大战starwar - BZOJ
- android智能家居在线语音控制
- javascript 用函数实现“继承”
- 检测CPU是否支持虚拟化
- Linux的文本处理工具浅谈-awk sed grep
- Hadoop问题:DataNode进程不见了
- Salesforce Lightning Builder Flows (Salesforce Lightning 构建Flows)
- cmake: error: symbol(s) not found for architecture x86_64 mac os 使用boost asio
- xpinyin模块
- Levmar 配置
- 5.Django高级
- [转]COPY OR MOVE FILES AND FOLDERS USING OLE AUTOMATION
- android studio 解决avd启动问题 ----waiting for target device come online
- easyui中使用的遮罩层