Leetcode226:Invert Binary Tree
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
to
4
/ \
7 2
/ \ / \
9 6 3 1
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* invertTree(struct TreeNode* root)
{
struct TreeNode *tmp;
if(root == NULL)
{
return NULL;
}
tmp = root->left;
root->left = invertTree(root->right);
root->right = invertTree(tmp);
return root; }
Leetcode226:Invert Binary Tree的更多相关文章
- leetcode:Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1即反转二叉树,代码如下: /** * Defin ...
- LeetCode OJ:Invert Binary Tree(反转二叉树)
Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...
- lintcode :Invert Binary Tree 翻转二叉树
题目: 翻转二叉树 翻转一棵二叉树 样例 1 1 / \ / \ 2 3 => 3 2 / \ 4 4 挑战 递归固然可行,能否写个非递归的? 解题: 递归比较简单,非递归待补充 Java程序: ...
- 【Invert Binary Tree】cpp
题目: Invert Binary Tree Total Accepted: 20346 Total Submissions: 57084My Submissions Question Solutio ...
- Python解Leetcode: 226. Invert Binary Tree
leetcode 226. Invert Binary Tree 倒置二叉树 思路:分别倒置左边和右边的结点,然后把根结点的左右指针分别指向右左倒置后返回的根结点. # Definition for ...
- 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 ...
- 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. ...
- <LeetCode OJ> 226. Invert Binary Tree
226. Invert Binary Tree Total Accepted: 57653 Total Submissions: 136144 Difficulty: Easy Invert a bi ...
随机推荐
- 事务&视图和索引
一:事务 1.含义:事务是一个不可分割的整体,事务中的多个执行过程,同生共死.要么都执行成功,要么都执行失败. 事务必须具备以下四个属性,(简称:ACID): ①.原子性(Atomicity):事务的 ...
- 图形编程(数值微分DDA)
#include <iostream> #include <time.h> #include <stdio.h> #include <stdlib.h> ...
- 【英语】Bingo口语笔记(8) - 爆破音的发音技巧
轻读,有时候甚至是听不到的,就嘴巴碰一下而已.
- 【英语】Bingo口语笔记(55) - work系列
- 决定undo表空间的大小
1.查询每秒最高需要的undo的数据块[每个块8k大小] sys)) from v$undostat; )) --------------------------------------------- ...
- grep -A -B选项详解和mysqlbinlog
grep的-A-B-选项详解(转)[@more@] grep能找出带有关键字的行,但是工作中有时需要找出该行前后的行,下面是解释 1. grep -A1 keyword filename 找出file ...
- Oracle RAC 负载均衡测试(结合服务器端与客户端)
Oracle RAC 负载均衡使得从客户端发起的连接能够有效地分配到监听器负载较小的实例上.有两种方式实现客户端负载均衡,一是通过配置客户端的load_balance,一是通过配置服务器端的remot ...
- for-in遍历json数据
1.for遍历json数据 ','fun':'前端开发'} for(var attr in json){ alert(json[attr]) //遍历json属性的数据 alert(json['nam ...
- Linux makefile教程之总述二[转]
Makefile 总述——————— 一.Makefile里有什么? Makefile里主要包含了五个东西:显式规则.隐晦规则.变量定义.文件指示和注释. 1.显式规则.显式规则说明了,如何生成一个或 ...
- Dubbo原理解析-注册中心之Zookeeper协议注册中心
下面我们来看下开源dubbo推荐的业界成熟的zookeeper做为注册中心, zookeeper是hadoop的一个子项目是分布式系统的可靠协调者,他提供了配置维护,名字服务,分布式同步等服务.对于z ...