Leetcode每日一题:226.invert-binary-tree(翻转二叉树)
思路:就是将节点的左指针指向右孩子,右指针指向左孩子,递归即可实现;
/*** 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){return NULL;}TreeNode *temp=root->left;root->left=invertTree(root->right);root->right=invertTree(temp);return root;}
};
Leetcode每日一题:226.invert-binary-tree(翻转二叉树)相关推荐
- leetcode python3 简单题226. Invert Binary Tree
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百二十六题 (1)题目 英文: Invert a binary tree. 中文 ...
- 226. Invert Binary Tree 翻转二叉树
翻转一棵二叉树. 示例: 输入: 4/ \2 7/ \ / \ 1 3 6 9 输出: 4/ \7 2/ \ / \ 9 6 3 1 备注: 这个问题是受到 Max Howell 的 原问题 启发的 ...
- LeetCode 226. Invert Binary Tree--反转二叉树--C++,Python解法--递归,迭代做法
题目地址:Invert Binary Tree - LeetCode Invert a binary tree. Example: Input: 4/ \2 7/ \ / \ 1 3 6 9 Outp ...
- 226. Invert Binary Tree 1
题目链接:Invert Binary Tree 思路: 如果需要反转一个二叉树,那么我们需要遍历整个树的所有节点. 如果想遍历所有的节点,我们可以用Depth First Search(DFS)或者B ...
- LeetCode #226 - Invert Binary Tree - Easy
Problem Invert a binary tree. Example 4/ \2 7/ \ / \ 1 3 6 9->4/ \7 2/ \ / \ 9 6 3 1 Algorithm 整理 ...
- leetcode 226. Invert Binary Tree
Invert a binary tree. 4/ \2 7/ \ / \ 1 3 6 9 to 4/ \7 2/ \ / \ 9 6 3 1 解法1: 本质是输的先序遍历 # Definition f ...
- Leetcode 226: Invert Binary Tree
问题描述: Given the root of a binary tree, invert the tree, and return its root. 将二叉树镜像 思路: 发现子问题:将给定二叉树 ...
- leetcode python3 简单题110. Balanced Binary Tree
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百一十题 (1)题目 英文: Given a binary tree, dete ...
- Leetcode-标签为Tree 226. Invert Binary Tree
原题 Invert a binary tree. 4/ \ 2 7/ \ / \ 1 3 6 9 to 4/ \ 7 2/ \ / \ 9 6 3 1 代码分析 反转二叉树 代码实现 public T ...
- [LeetCode][JavaScript]Invert Binary Tree 反转二叉树
反转二叉树 其实我从没有想到前端面试会问到这个问题,题目来源于google的面试 Google: 90% of our engineers use the software you wrote (Ho ...
最新文章
- linux下备份mysql上传到网盘_Linux命令行上传文件到百度网盘
- 一起聊聊好玩的Openresty
- php 时间 插件,PHP中Carbon日期时间处理利器详解
- android dialog 隐藏状态栏_Android开发不得不收集的工具类集合
- 自带的数据集_机器学习练习数据哪里找?两行代码搞定!
- 江苏涟水中学2021高考成绩查询,2021年涟水县高考状元名单资料,今年涟水县高考状元多少分...
- MyEclipse导入jquery-1.8.0.min.js等文件报错的解决方案
- Unfair contest(个人做法)
- 【Linux】Linux按tab键补全文件(名)或路径不区分大小写
- Bailian2801 填词 POJ1629 ZOJ1546 Fillword【排序】
- GridView常见问题及解决办法
- 前端设备通过Ehome协议接入EasyCVR平台无法播放问题解决
- matlab菲涅尔衍射光强分布,求助!!!用颜色表示的菲涅尔衍射的光强分布图
- matlab 低级图形错误,matlab图形底层错误(matlab崩溃前的数据恢复)
- 【Seen看世界】:像高智商人群看齐
- 心率检测实现报告(三)
- [2018 CS:GO Server]2018 Old CSGO 服务端,回忆逝去的青春!
- 仓库无证如何处罚_无证经营一般是怎么处罚的啊
- java 设计模式 路由器_Java设计模式——工厂模式
- FL Studio2022水果编曲音乐制作软件自带完整插件