[귀속] 검지offer--면접문제 19:두 갈래 나무의 거울
2305 단어 검지offer 제목 노트
검지offer--면접문제19:두 갈래 나무의 거울
Solution1: 역귀해법, 명심하세요!뿌리 결점이 비어 있는 경우 쉽게 새니 주의하세요!
/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Solution {//
public:
void Mirror(TreeNode *pRoot) {
if(pRoot == 0)// return
return;
if(pRoot->left == NULL && pRoot->right == NULL)// ,return
return;
struct TreeNode *temp;
if(pRoot->left != NULL || pRoot->right != NULL){// ,
temp = pRoot->left;
pRoot->left = pRoot->right;
pRoot->right = temp;
}
if(pRoot->left)
Mirror(pRoot->left);
if(pRoot->right)
Mirror(pRoot->right);
}
};
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
검지offer--면접문제 30:최소 K개수채소 새를 만드는 방법, 순서를 정한 후 앞의 k개 수를 선택한다.복잡도는 O(nlogn) O(n l o g n) 정렬로 코드를 손쉽게 배열하거나 라이브러리 함수sort()를 이용하면 힘을 아끼기 위해sort()를 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.