226.[LeetCode]Invert Binary Tree

1692 단어 LeetCode

제목:


두 갈래 나무 반전

귀속:

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

좋은 웹페이지 즐겨찾기