1. Invert Binary Tree My Submissions QuestionEditorial Solution

    Total Accepted: 87818 Total Submissions: 193396 Difficulty: Easy

    Invert a binary tree.

    4

    / \

    2 7

    / \ / \

    1 3 6 9

    to

    4

    / \

    7 2

    / \ / \

    9 6 3 1

    逆转一颗二叉树

    思路:so easy

/**
* 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 *tnode;
tnode = root->left;
root->left = root->right;
root->right = tnode;
invertTree(root->left);
invertTree(root->right);
return root;
}
};

37-Invert Binary Tree的更多相关文章

  1. 【07_226】Invert Binary Tree

    Invert Binary Tree Total Accepted: 54994 Total Submissions: 130742 Difficulty: Easy Invert a binary ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. C#版 - 226. Invert Binary Tree(剑指offer 面试题19) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - 2 ...

  6. [LintCode] Invert Binary Tree 翻转二叉树

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  7. LeetCode—— Invert Binary Tree

    LeetCode-- Invert Binary Tree Question invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 ...

  8. 【Invert Binary Tree】cpp

    题目: Invert Binary Tree Total Accepted: 20346 Total Submissions: 57084My Submissions Question Solutio ...

  9. <LeetCode OJ> 226. Invert Binary Tree

    226. Invert Binary Tree Total Accepted: 57653 Total Submissions: 136144 Difficulty: Easy Invert a bi ...

  10. LeetCode_226. Invert Binary Tree

    226. Invert Binary Tree Easy Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: ...

随机推荐

  1. seata序列化日期类型出错

    一.背景 最近在整合seata的过程中,发现如果业务表中存在 datetime 的数据类型,那么在分布式事务中,修改这个字段的值时,会出现如下错误.此处提供2种解决方案. com.fasterxml. ...

  2. 力扣 - 剑指 Offer 57. 和为s的两个数字

    题目 剑指 Offer 57. 和为s的两个数字 思路1(哈希表) 这题首先想到的是使用两个for遍历,查找是哪两个相加等于target,但是时间复杂度确实\(O(N^2)\),时间复杂度太高,因此我 ...

  3. Noip模拟37 2021.8.12

    T1 数列 真是考场上不是数学的乱推柿子,想定理,是数学的没想出来.. 比较悲伤... 列柿子不用动脑子,就是没有想出来$EXgcd$解不定方程,淦.. 解处一组解后利用比较显然的性质: $x+\fr ...

  4. Pogo-Cow S

    这题出在单调队列优化dp里,就离谱好吧...... 对不住了上来先喷一波,不过离谱是确实的 dp的含义也很简单,就是说从j到i的分数最大值 直接上代马,里面说的很详细了 1 #include<b ...

  5. Python课程笔记(二)

    1.格式化输出 print("%d %d %s" % (15, 3.14, 12.8)) 对比C语言 printf("%d,%d,%s",15, 3.14, 1 ...

  6. 洛谷 P4587 [FJOI2016]神秘数

    大鸽子 llmmkk 正在补8.3号咕掉的题 时隔两个月,再看到这道题,我又是一脸懵,这种思维的培养太重要了 链接: P4587 题意: 给出 \(n\) 个点的序列,\(m\) 次询问区间神秘数. ...

  7. 《手把手教你》系列技巧篇(三十六)-java+ selenium自动化测试-单选和多选按钮操作-番外篇(详解教程)

    1.简介 前边几篇文章是宏哥自己在本地弄了一个单选和多选的demo,然后又找了网上相关联的例子给小伙伴或童鞋们演示了一下如何自动化测试,这一篇宏哥在网上找了一个问卷调查,给小伙伴或童鞋们来演示一下.上 ...

  8. python write() argument must be str, not bytes

    python pickle from __future__ import absolute_import from __future__ import division from __future__ ...

  9. hdu 2159 FATE(DP)

    题意: 小余玩游戏,离最后一级还需n的经验值,但是他已经很厌烦了,还剩下m的忍耐度.每杀一只怪小余会得到相应的经验,同时减掉相应的忍耐度. 当忍耐度降到0或者0以下时,小余就不会再玩这个游戏.小余还说 ...

  10. coreseek使用心得

    基本使用方法: D:\coreseek-4.1\bin\searchd -c D:\coreseek-4.1\etc\article.conf --stop 停止服务 D:\coreseek-4.1\ ...