zoukankan      html  css  js  c++  java
  • [leetcode] Invert binary tree.

    Invert a binary tree.

    class Solution {
    public:
        TreeNode* invertTree(TreeNode* root) {
            TreeNode* temp;
            if(root)
            {
                temp=root->left;
                root->left=root->right;
                root->right=temp;
                if(root->left) invertTree(root->left);
                if(root->right) invertTree(root->right);
            }
            return root;
        }
    };
    

      1. 错:把if用成while。while和递归可以互换

  • 相关阅读:
    CSS样式2
    页面布局
    CSS样式1
    HTML
    Document
    Document
    Document
    Document
    Document
    Document
  • 原文地址:https://www.cnblogs.com/yuchenkit/p/5253032.html
Copyright © 2011-2022 走看看