Invert Binary Tree(easy)
来源:互联网 发布:爱因斯坦人工智能名言 编辑:程序博客网 时间:2024/04/19 20:07
1.直接把递归把左右子树翻转即可
AC代码:
/** * 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: void invert(TreeNode* root) { if (root != NULL) { swap(root->left, root->right); invert(root->left); invert(root->right); } } TreeNode* invertTree(TreeNode* root) { invert(root); return root; } };
0 0
- Invert Binary Tree(easy)
- 226. Invert Binary Tree (Easy)
- 【leetcode】【Easy】【226. Invert Binary Tree】【tree】
- [Leetcode 226, Easy] Invert Binary Tree
- <LeetCode><Easy>226Invert a binary tree
- 226. Invert Binary Tree [easy] (Python)
- Easy-题目4:226. Invert Binary Tree
- Leetcode 226. Invert Binary Tree (Easy) (cpp)
- Easy 226题 Invert Binary Tree
- LeetCode #226 - Invert Binary Tree - Easy
- 【Leetcode-easy-226】Invert Binary Tree
- 226. Invert Binary Tree Difficult: Easy
- LeetCode 226. Invert Binary Tree (Easy)
- leetcode 226 Invert Binary Tree(难易度:Easy)
- LintCode | Easy | 翻转二叉树 | Invert Binary Tree
- Leet Code OJ 226. Invert Binary Tree [Difficulty: Easy]
- 226.leetcode Invert Binary Tree(easy)[二叉树 递归]
- [leetcode] Invert Binary Tree
- 2.1 状态空间表示
- UVa-11292 - Dragon of Loowater:简单题
- ISE使用IP核生成的SRAM,读写需要时钟的原因
- Servlet中的GET和POST之间的区别
- 关于DefaultTypeConverter工作原理以及totype参数
- Invert Binary Tree(easy)
- 关于C 中快排函数QSORT的用法
- heheda练数据结构
- HDU4324-Triangle LOVE-判断是否存在环(拓扑)
- 多线程——原子、非原子,自旋锁和互斥锁
- Web Service基础篇(一)之AXIS2
- Java学习笔记--组合数学
- 使用TCP协议的NAT穿透技术 (转)
- Android自动获得短信验证码