zoukankan      html  css  js  c++  java
  • 37-Invert Binary Tree

    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;
        }
    };
  • 相关阅读:
    linux-满足多字符条件统计行数
    oracle的面试问题
    在开发过程中为什么需要写存储过程
    面向对象编程
    动态SQL
    触发器

    子程序
    游标
    集合
  • 原文地址:https://www.cnblogs.com/freeopen/p/5482932.html
Copyright © 2011-2022 走看看