226. Invert Binary Tree (Easy)
来源:互联网 发布:非诚勿扰网络更新时间 编辑:程序博客网 时间:2024/04/20 23:43
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
Solution:
C:
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */struct TreeNode* invertTree(struct TreeNode* root) { if(root == NULL) { return NULL; } if(!root->left && !root->right) { return root; } struct TreeNode* temp = root->left; root->left = root->right; root->right = temp; invertTree(root->left); invertTree(root->right); return root;}
使用递归实现二叉树的反转(镜像)
0 0
- 226. Invert Binary Tree (Easy)
- 【leetcode】【Easy】【226. Invert Binary Tree】【tree】
- Invert Binary Tree(easy)
- 226. Invert Binary Tree [easy] (Python)
- Easy-题目4:226. Invert Binary Tree
- Leetcode 226. Invert Binary Tree (Easy) (cpp)
- 226. Invert Binary Tree Difficult: Easy
- LeetCode 226. Invert Binary Tree (Easy)
- Leet Code OJ 226. Invert Binary Tree [Difficulty: Easy]
- 226.leetcode Invert Binary Tree(easy)[二叉树 递归]
- [Leetcode 226, Easy] Invert Binary Tree
- <LeetCode><Easy>226Invert a binary tree
- Easy 226题 Invert Binary Tree
- LeetCode #226 - Invert Binary Tree - Easy
- 【Leetcode-easy-226】Invert Binary Tree
- 226.Invert Binary Tree
- 226. Invert Binary Tree
- 226. Invert Binary Tree
- Partition List
- C++派生类改变基类的成员访问类型
- Java常见错误列表
- JavaScript基础练习
- 系统吞吐量和系统并发数以及响时间的关系理解
- 226. Invert Binary Tree (Easy)
- 自学 Swift整理
- MySQL数据库的用户权限使用和数据的备份和恢复
- 【Struts2】Struts2中拦截器
- uml(七) 状态图
- IP Forwarding打开
- Linux网络通信TCP/IP
- javascript中函数的使用
- Android Studio 导入第三方库