[Leetcode] 226. Invert Binary Tree 解题报告
来源:互联网 发布:2016淘宝女鞋店铺排行 编辑:程序博客网 时间:2024/05/21 22:27
题目:
Invert a binary tree.
4 / \ 2 7 / \ / \1 3 6 9to
4 / \ 7 2 / \ / \9 6 3 1Trivia:
This problem was inspired by this original tweet by Max Howell:
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.
思路:
没什么可说的。。。
代码:
/** * 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 != NULL) { TreeNode *node = root->left; root->left = root->right; root->right = node; invertTree(root->left); invertTree(root->right); } return root; }};
阅读全文
0 0
- [leetcode] 226. Invert Binary Tree 解题报告
- 【LeetCode】226. Invert Binary Tree 解题报告
- LeetCode 226.Invert Binary Tree 解题报告
- [Leetcode] 226. Invert Binary Tree 解题报告
- LeetCode-Invert Binary Tree-解题报告
- 【LeetCode】Invert Binary Tree 解题报告
- 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
- LeetCode #226. Invert Binary Tree
- [LeetCode]226. Invert Binary Tree
- 226. Invert Binary Tree LeetCode
- LeetCode 226. Invert Binary Tree
- LeetCode 226. Invert Binary Tree
- leetcode:226. Invert Binary Tree
- LeetCode 226. Invert Binary Tree
- 使用Restify+superagent做数据转发
- 宝宝如何喝水最科学,做家长的一定要知道
- Java编译时多态和运行时多态
- 第十八周:[leetCode] 74. Search a 2D Matrix
- vue学习之vue-resource
- [Leetcode] 226. Invert Binary Tree 解题报告
- js基础进阶2-3 面向对象(继承)
- 多线程jion方法
- Android进程的内存管理分析
- leetcode 34. Search for a Range
- C++学习(54)
- crontab hadoop任务没有执行
- python学习笔记完整版
- MVC面试问题与答案