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