예제 #1
0
 bool mirrorTree(TreeNode *t1, TreeNode *t2){
     if(t1 == NULL && t2 == NULL)
         return true;
     if((t1 == NULL && t2 != NULL) || (t1 != NULL && t2 == NULL))
         return false;
     return (t1->val == t2->val) && mirrorTree(t1->left , t2->right) && mirrorTree(t1->right, t2->left);
 }
예제 #2
0
TreeNode *mirrorTree(TreeNode *root) {
	if (!root) return 0;
	TreeNode *left = root->left;
	root->left = mirrorTree(root->right);
	root->right = mirrorTree(left);
	
	return root;
}
예제 #3
0
파일: bstHelper.c 프로젝트: saikatroyc/bst
void mirrorTree(pnode *root) {
    pnode temp;
    if (*root == NULL) return;
    if ((*root)->left == NULL && (*root)->right == NULL) return;

    mirrorTree(&((*root)->left));
    mirrorTree(&((*root)->right));
    temp = (*root)->left;
    (*root)->left = (*root)->right;
    (*root)->right= temp;
    return;
}
예제 #4
0
파일: off.cpp 프로젝트: JavaZhangYin/coding
// to mirror a tree, we mirror the left and right child recursively. 
bool mirrorTree(BTreeNode *tree) {
  if(NULL == tree) return true; 

  // exchange the left and right subtree. 
  BTreeNode *tmpNode = tree->left; 
  tree->left = tree->right; 
  tree->right = tmpNode; 

  // mirror recursively the subtrees. 
  mirrorTree(tree->left); 

  mirrorTree(tree->right); 

  return true; 
}
예제 #5
0
 bool isSymmetric(TreeNode *root) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     if(root == NULL)
         return true;
     return mirrorTree(root->left, root->right);
 }