LeetCode:226. 翻转二叉树
生活随笔
收集整理的這篇文章主要介紹了
LeetCode:226. 翻转二叉树
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
226. 翻轉(zhuǎn)二叉樹
- 題目:
- 解題思路:
- 源碼:
- 踩坑點:
題目:
解題思路:
用遞歸的方法將二叉樹的左右節(jié)點互換,核心思想就是交換
源碼:
struct TreeNode* invertTree(struct TreeNode* root){if(root == NULL)return NULL;struct TreeNode* tmp = root -> left;root->left = invertTree(root->right);root->right = invertTree(tmp);return root; }踩坑點:
一定要判斷是否二叉樹為空
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎!定制產(chǎn)品紅包拿不停!總結(jié)
以上是生活随笔為你收集整理的LeetCode:226. 翻转二叉树的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu-桌面版-常用设置
- 下一篇: How does a relationa