LeetCode 226. Invert Binary Tree (Easy)
来源:互联网 发布:澳洲传媒硕士 知乎 编辑:程序博客网 时间:2024/04/18 11:05
题目描述:
Invert a binary tree.
Example:
4 / \ 2 7 / \ / \1 3 6 9 to 4 / \ 7 2 / \ / \9 6 3 1
题目大意:反转二叉树。
思路:递归,直接交换。
主要是题目里这个比较搞笑:
Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.
大概意思是说写出Homebrew的老哥因为不会反转二叉树而被google拒了。
c++代码:
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* invertTree(TreeNode* root) { if (root == nullptr) return root; auto temp = root->left; root->left = root->right; root->right = temp; invertTree(root->left); invertTree(root->right); return root; }};
阅读全文
0 0
- 【leetcode】【Easy】【226. Invert Binary Tree】【tree】
- Leetcode 226. Invert Binary Tree (Easy) (cpp)
- LeetCode 226. Invert Binary Tree (Easy)
- 226. Invert Binary Tree (Easy)
- 226.leetcode Invert Binary Tree(easy)[二叉树 递归]
- [Leetcode 226, Easy] Invert Binary Tree
- <LeetCode><Easy>226Invert a binary tree
- LeetCode #226 - Invert Binary Tree - Easy
- 【Leetcode-easy-226】Invert Binary Tree
- Invert Binary Tree(easy)
- 226. Invert Binary Tree [easy] (Python)
- Easy-题目4:226. Invert Binary Tree
- 226. Invert Binary Tree Difficult: Easy
- LeetCode 226. Invert Binary Tree
- [leetcode] 226.Invert Binary Tree
- [leetcode] 226. Invert Binary Tree
- 【LeetCode】226. Invert Binary Tree
- leetCode 226. Invert Binary Tree
- unbuntu运行gcc出现collect2: fatal error: cannot find 'ld'
- display:flex 布局教程 (赞,清晰)
- cain使用教程
- 苹果支持WebRTC
- CO01涉及到的透明表
- LeetCode 226. Invert Binary Tree (Easy)
- Android JNI报错:java.lang.UnsatisfiedLinkError: Native method not found ..........解决办法
- 查看linux系统内存使用情况
- 意外泄露!!!室友的C语言考了99分竟然是因为这张图...
- 在IDEA中创建maven项目
- 有些感慨
- 51Nod 1459 迷宫游戏
- java 基于poi 写入excel 合并单元格
- LoRa技术如何使供应链和资产管理变得更智能