226. Invert Binary Tree(Tree)

原创 2018年04月16日 21:35:41

https://leetcode.com/problems/invert-binary-tree/description/

题目:将二叉树进行翻转

思路:使用BFS进行遍历,然后交换每个结点的左右子节点。

class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {
              if(!root) return root;

              TreeNode *q[10000];
              int l=0,r=1;
              q[l]=root;
              while(l<r){

                   if(q[l]){
                      TreeNode *temp = q[l]->left;
                      q[l]->left = q[l]->right;
                      q[l]->right=temp;
                      q[r]=q[l]->left;
                      r++;
                      q[r]=q[l]->right;
                      r++;
                   }

                  l++;
              }
             return root;
    }
};
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tangyuanzong/article/details/79967021

防破解问答集

防破解问答集 当发现自己为之工作了好几个月,甚至几年的程序被人破解的时候,所受的伤害是难以形容的。 我作为一个共享软件作者,并不是因为我在乎那几块钱而已(...
  • oldsword
  • oldsword
  • 2001-01-29 19:32:00
  • 1061

226. Invert Binary Tree [easy] (Python)

题目链接https://leetcode.com/problems/invert-binary-tree/题目原文 Invert a binary tree. 4 / \ ...
  • coder_orz
  • coder_orz
  • 2016-05-12 14:36:34
  • 1464

【LeetCode】226. Invert Binary Tree 解题报告

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51471280Subject 出处:https://leetcode.com/pro...
  • crazy1235
  • crazy1235
  • 2016-05-29 00:18:13
  • 10981

leetcode(226)—— Invert Binary Tree(Python/C++)

Invert Binary Tree法一:简单递归class Solution { public: TreeNode* invertTree(TreeNode* root) { ...
  • lanchunhui
  • lanchunhui
  • 2016-04-15 14:57:52
  • 542

leetcode 226 Invert Binary Tree 翻转二叉树

大牛没有能做出来的题,我们要好好做一做     Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to ...
  • wangyaninglm
  • wangyaninglm
  • 2015-06-23 23:53:58
  • 3058

leetcode 226: Invert Binary Tree

leetcode 226: Invert Binary Tree python java c++
  • xudli
  • xudli
  • 2015-06-19 01:07:09
  • 4946

226. Invert Binary Tree的C++解法

考虑到要遍历整棵树,所以选了广度优先遍历的方法,把每个节点加入队列之后交换它的左右子树指针就好了。 /** * Definition for a binary tree node. * stru...
  • musechipin
  • musechipin
  • 2017-04-06 10:37:37
  • 125

Leetcode 226: Invert Binary Tree(二叉树反转 递归、非递归实现)

nvert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 ...
  • sunao2002002
  • sunao2002002
  • 2015-06-13 14:41:43
  • 14942

1102. Invert a Binary Tree (25)-PAT甲级真题

1102. Invert a Binary Tree (25) The following is from Max Howell @twitter: Google: 90% of ou...
  • liuchuo
  • liuchuo
  • 2016-08-10 20:04:01
  • 167

【PAT】1102. Invert a Binary Tree (25)

The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote ...
  • realxuejin
  • realxuejin
  • 2015-10-24 19:19:54
  • 673
收藏助手
不良信息举报
您举报文章:226. Invert Binary Tree(Tree)
举报原因:
原因补充:

(最多只允许输入30个字)