Invert Binary Tree(easy)
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;
} };
Invert Binary Tree(easy)的更多相关文章
- Leetcode 226. Invert Binary Tree(easy)
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...
- LeetCode_226. Invert Binary Tree
226. Invert Binary Tree Easy Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: ...
- 【07_226】Invert Binary Tree
Invert Binary Tree Total Accepted: 54994 Total Submissions: 130742 Difficulty: Easy Invert a binary ...
- C#版 - 226. Invert Binary Tree(剑指offer 面试题19) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - 2 ...
- <LeetCode OJ> 226. Invert Binary Tree
226. Invert Binary Tree Total Accepted: 57653 Total Submissions: 136144 Difficulty: Easy Invert a bi ...
- lc面试准备:Invert Binary Tree
1 题目 Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 接口: public TreeNod ...
- 226. Invert Binary Tree(C++)
226. Invert Binary Tree Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 ...
- LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree
258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...
- [LintCode] Invert Binary Tree 翻转二叉树
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
随机推荐
- POJ 1200 Crazy Search 字符串的Hash查找
第一次涉及HASH查找的知识 对于字符串的查找有很多前人开发出来的HASH函数,比较常用的好像是ELF 和 BKDR. 这道题没想到突破点是在于其nc值,告诉你组成字符串的字母种类. 还有用26进制, ...
- 201609-2 火车购票 Java
思路待补充 import java.util.Scanner; class Main{ public static void main(String[] args) { //100个座位 int[] ...
- linux messages日志出现kernel: nf_conntrack: table full, dropping packet
上述结果会让业务访问很慢!各种网络服务耗时大幅上升,各种time out,各种丢包,完全无法正常提供服务,大并发业务场景下,开防火墙很容易出现这种问题. 解决方法1:关闭分防火墙服务 解决方法2:修改 ...
- 面试准备 css 书写顺序及原理
书写顺序 (1)定位属性:position display float left top right bottom overflow clear z-index (2)自身属性: ...
- JaveSE--getResource
System.out.println(ConfigUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath()); ...
- Thread--生产者消费者
2个生产者,2个消费者,库存容量2 package p_c_allWait.copy; import java.util.LinkedList; import java.util.List; publ ...
- Linux(CENTOS7) Tomcat服务成功发布但局域网浏览器无法访问
问题 : 我在linux搭建了一个tomcat服务器,tomcat开启后,发现在局域网浏览器上无法访问该tomcat,浏览器报无法访问服务器错误,我查看了tomcat的日志,路径..../tomcat ...
- 加速软件源更新和安装 ubuntu 软件中心
Linux mint 12 修改加速软件源更新和安装 ubuntu 软件中心 由于 linux mint 12 是基于 ubuntu 的,可以使用 ubuntu 的源(Ubuntu 11.10 代号 ...
- OpenMP笔记(一)
原文:https://www.bearoom.xyz/2019/02/17/openmp1/ 并行技术有很多种,OpenMP算是比较简单可用的一种,OpenMP全称是 Open Multi-Proce ...
- // 生成modbus CRC16数据
CRC- / MODBUS : )CRC寄存器初始值为 FFFF:即16个字节全为1: )CRC- / MODBUS的多项式A001H ( 0001B) ‘H’表示16进制数,‘B’表示二进制数 计算 ...