[LC] 156. Binary Tree Upside Down
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that shares the same parent node) or empty, flip it upside down and turn it into a tree where the original right nodes turned into left leaf nodes. Return the new root.
Example:
Input: [1,2,3,4,5]
1
/ \
2 3
/ \
4 5
Output: return the root of the binary tree [4,5,2,#,#,3,1]
4
/ \
5 2
/ \
3 1
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode upsideDownBinaryTree(TreeNode root) {
if (root == null || root.left == null) {
return root;
}
TreeNode newNode = upsideDownBinaryTree(root.left);
root.left.left = root.right;
root.left.right = root;
root.left = null;
root.right = null;
return newNode;
}
}
[LC] 156. Binary Tree Upside Down的更多相关文章
- ✡ leetcode 156. Binary Tree Upside Down 旋转树 --------- java
156. Binary Tree Upside Down Add to List QuestionEditorial Solution My Submissions Total Accepted: ...
- 156. Binary Tree Upside Down反转二叉树
[抄题]: Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left nod ...
- 156. Binary Tree Upside Down
题目: Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node ...
- [LeetCode#156] Binary Tree Upside Down
Problem: Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left ...
- [leetcode]156.Binary Tree Upside Down颠倒二叉树
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that ...
- [LeetCode] 156. Binary Tree Upside Down 二叉树的上下颠倒
Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node that ...
- 【LeetCode】156. Binary Tree Upside Down 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 迭代 日期 题目地址:https://leet ...
- [Locked] Binary Tree Upside Down
Binary Tree Upside Down Given a binary tree where all the right nodes are either leaf nodes with a s ...
- 【LeetCode】Binary Tree Upside Down
Binary Tree Upside Down Given a binary tree where all the right nodes are either leaf nodes with a s ...
随机推荐
- python + selenium +win32gui + winspy 实现图片上传
过程:模拟点击上传按钮,打开Windows对话框,编辑栏输入文件路径(或网址)点击确定.网上随便找了一个进行测试. 点击后出现Windows上传对话框 用 winspy 来检测窗口的句柄 python ...
- RK3399开发板Android镜像烧写之Windows系统映像烧写
4.1.1 l RKTool 驱动安装(基于迅为iTOP-3399开发板)DriverAssitant_v4.5.zip 文件,打开 驱动安装成功,如下图: 注意事项:1.目前支持的操作系统包括:X ...
- (4)关于Alpha通道问题
其实,我还是不理解,我还是先把我目前懂得和觉得有用的东西先存下来 =================================================================== ...
- apache安装和mysql php配置问题
apache下载和安装: 下载网址:http://httpd.apache.org/ 然后 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ ...
- 1月18日 LCA专项训练
A. Lorenzo Von Matterhorn B.Minimum spanning tree for each edge C.Misha, Grisha and Underground D.Fo ...
- render_template()的各种用法
1.可以有很多个参数,第一个一定是模板的名字 2.可以传字典.列表.单个变量等等,还可以传函数,在模板中调用函数 后端函数: from flask import Flask from flask im ...
- 常用的tensorflow函数
在mask_rcnn常用的函数 1 tf.cast(): https://blog.csdn.net/dss875914213/article/details/86558407 2 tf.ga ...
- 如何解决Tomcat端口号被占用
在eclipse中配置好tomcat服务器后,启动时提示错误如下图 提示端口被占用. 第一种方法: 结束占用端口的进程 第一步:netstat -aon|findstr "端口号" ...
- 计算机网络(2): http的基础上用SSL或TSL加密
加密过程具体TCP实现 步骤 1 : 客户端通过发送Client Hello报文开始SSL通信(这里是在TCP的三次握手已经完成的基础上进行的).报文中包含客户端支持的SSL的指定版本.加密组件列表( ...
- 吴裕雄--天生自然 JAVA开发学习:Character 类
char ch = 'a'; // Unicode 字符表示形式 char uniChar = '\u039A'; // 字符数组 char[] charArray ={ 'a', 'b', 'c', ...