simple recursion Swap 0ms C++


  • 1
    K

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


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.