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);
}
}

最新文章

  1. C# 之 DataReader 和 DataSet 的区别
  2. CodeForces 455D 分块
  3. iOS---初识Swift(一)
  4. MVC, MVP, MVVM比较以及区别
  5. archlinux更新错误
  6. C++中关于cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
  7. 1015: [JSOI2008]星球大战starwar - BZOJ
  8. android智能家居在线语音控制
  9. javascript 用函数实现“继承”
  10. 检测CPU是否支持虚拟化
  11. Linux的文本处理工具浅谈-awk sed grep
  12. Hadoop问题:DataNode进程不见了
  13. Salesforce Lightning Builder Flows (Salesforce Lightning 构建Flows)
  14. cmake: error: symbol(s) not found for architecture x86_64 mac os 使用boost asio
  15. xpinyin模块
  16. Levmar 配置
  17. 5.Django高级
  18. [转]COPY OR MOVE FILES AND FOLDERS USING OLE AUTOMATION
  19. android studio 解决avd启动问题 ----waiting for target device come online
  20. easyui中使用的遮罩层

热门文章

  1. 洛谷P3372 【模板】线段树 1
  2. Excel—“撤销工作表保护密码”的破解并获取原始密码
  3. js 分享到按钮
  4. ARCGIS对谷歌影像进行投影转换
  5. WebStorage 和 Cookie的区别
  6. localstorage,sessionstorage使用
  7. textview 多行 省略号
  8. js中~~的用法
  9. [转载] 4. JebAPI 之 jeb.api.ui
  10. 使用apache和htaccess对目录访问设置密码保护配置教程