LeetCode226 InvertBinaryTree Java题解
题目:
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
解答:
遍历每个节点 直接交换他们的左右节点
代码:
public static TreeNode invertTree(TreeNode root) {
if(root!=null)
{
TreeNode temNode=root.left;
root.left=root.right;
root.right=temNode;
invertTree(root.left);
invertTree(root.right);
}
return root;
}
LeetCode226 InvertBinaryTree Java题解的更多相关文章
- 【剑指offer】(第 2 版)Java 题解
[剑指offer](第 2 版)Java 题解 第一章 面试的流程 略... 第二章 面试需要的基础知识 面试题 1. 赋值运算符函数 面试题 2. 实现 Singleton 模式 Solution ...
- 试题 历届试题 核桃的数量 java题解
资源限制 时间限制:1.0s 内存限制:256.0MB 问题描述 小张是软件项目经理,他带领3个开发组.工期紧,今天都在加班呢.为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑).他的要求是: ...
- TopCoder SRMS 1 字符串处理问题 Java题解
Problem Statement Let's say you have a binary string such as the following: 011100011 One way to e ...
- LeetCode108_Convert SortedArray to BinarySearchTree(将有序数组转成二叉排序树) Java题解
题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST ...
- 7.15实习培训日志 java题解
周末总结 本周主要学习了markdown,git,docker等工具的使用.在本周的学习中,初步了解了markdown,git,docker的使用.本周的静态博客部署中,对于怎么显示一个博客内容,有两 ...
- LeetCode234_PalindromeLinkedList (推断是否为回文链表) Java题解
题目: Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) ...
- CF1256(div3 java题解)
A: 题意:给定A个N元,B个一元,问是否可以凑成S元. 思路:A*i+j=S 即 A*I<=S<=A*I+B 即min(S/N,A)+B>=S: /* @author nimphy ...
- L1-027 出租 (20 分) java题解
下面是新浪微博上曾经很火的一张图: 一时间网上一片求救声,急问这个怎么破.其实这段代码很简单,index数组就是arr数组的下标,index[0]=2 对应 arr[2]=1,index[1]=0 对 ...
- L1-023 输出GPLT (20 分) java题解 GPLT天梯赛防坑技巧
上题目先 给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符.当然,四种字符(不区分大小写)的个数不一定是一样多的 ...
随机推荐
- AC日记——Little Elephant and Function codeforces 221a
A - Little Elephant and Function 思路: 水题: 代码: #include <cstdio> #include <iostream> using ...
- Codeforces 954H Path Counting(DP)
题目链接 Path Counting 题意 给定一棵高度为$n$的树,给出每一层的每个点的儿子个数(某一层的所有点儿子个数相同). 令$f_{k}$为长度为$k$的路径条数,求$f_{1}, ...
- KD-Tree复习笔记(BZOJ1941 & BZOJ2648 & BZOJ4066)
快一年了都没碰到什么必须用KDT的题目导致模板完全忘光了,重新复习了一下. K_Dimention_Tree是一种用来处理二维以上问题的数据结构(OI中一般都是二维),本质是二维启发式估价函数实现剪枝 ...
- CocoaPods 错误 target overrides the `OTHER_LDFLAGS`...
Xcode 升级到 6.0 后,更新 CocoaPods,出现了如下的警告 [!] The `Paopao [Debug]` target overrides the `PODS_ROOT` buil ...
- PHP switch的“高级”用法详解
只所以称为“高级”用法,是因为我连switch的最基础的用法都还没有掌握,so,接下来讲的其实还是它的基础用法! switch 语句和具有同样表达式的一系列的 IF 语句相似.很多场合下需要把同一个变 ...
- kaptcha验证码
@Action("/validimg") public String validimg() throws Exception { genernateCaptchaImage(); ...
- Signing Identities, Missing Private Key, Cannot sign App
这个问题发生在重新安装系统后,丢失了之前的private key等.所以解决方法就是提示的revoke and request. 到developer center中找到certificate中对应的 ...
- applicationContext.xml文件如何调用外部properties等配置文件
只需要在applicationContext.xml文件中添加一行: <!-- 导入外部的properties文件 --> <context:property-placeholder ...
- Qt creator发布可执行文件方式----靠谱
1.首先用 QtCreator 新建一个 Qt Widgets Application 项目,直接用默认的 QMainWindow 程序就可以了,项目名字假定是serial_port.exe. 然后以 ...
- 常见java异常
1. java.lang.NullPointerException(空指针异常) 调用了未经初始化的对象或者是不存在的对象 经常出现在创建图片,调用数组这些操作中,比如图片未经初始化,或者图片创建时 ...