226. Invert Binary Tree
生活随笔
收集整理的這篇文章主要介紹了
226. Invert Binary Tree
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
做法就是:
如果root是null,返回
swap左右兩樹(用tmp作為第三個容器),然后對左右子樹遞歸
返回root
1 public TreeNode invertTree(TreeNode root) { 2 if(root == null) { 3 return null; 4 } 5 TreeNode tmp = root.left; 6 root.left = root.right; 7 root.right = tmp; 8 invertTree(root.left); 9 invertTree(root.right); 10 return root; 11 }?
轉載于:https://www.cnblogs.com/warmland/p/5706043.html
總結
以上是生活随笔為你收集整理的226. Invert Binary Tree的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript学习笔记-JSON对
- 下一篇: 暑假集训(3)第二弹 -----Jung