LintCode - 175.두 갈래 나무를 뒤집다
                                            
 888 단어  LintCode
                    
당신은 실제 면접에서 이 문제를 만난 적이 있습니까?
Yes
예제
  1         1
 / \       / \
2   3  => 3   2
   /       \
  4         4/**
 * Definition of TreeNode:
 * class TreeNode {
 * public:
 *     int val;
 *     TreeNode *left, *right;
 *     TreeNode(int val) {
 *         this->val = val;
 *         this->left = this->right = NULL;
 *     }
 * }
 */
class Solution {
public:
    /**
     * @param root: a TreeNode, the root of the binary tree
     * @return: nothing
     */
    void invertBinaryTree(TreeNode *root) {
        // write your code here
        if( root == NULL ) return;
        
        TreeNode* node = root->left;
        root->left = root->right;
        root->right = node;
        
        invertBinaryTree( root->left );
        invertBinaryTree( root->right );
    }
};이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
lintcode--94. 두 갈래 나무의 최대 경로와두 갈래 트리를 제시하고 경로와 최대를 찾을 수 있습니다. 경로는 어느 노드에서 시작하고 끝낼 수 있습니다. (경로와 두 노드 사이에 있는 경로의 노드 값의 합) 두 갈래 나무 한 그루를 주시오. 되돌아오다 뒷순서에...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.