mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										32
									
								
								24/04/1379.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								24/04/1379.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by szh2 on 24-4-3.
 | 
			
		||||
//
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
struct TreeNode {
 | 
			
		||||
    int val;
 | 
			
		||||
    TreeNode *left;
 | 
			
		||||
    TreeNode *right;
 | 
			
		||||
 | 
			
		||||
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Solution{
 | 
			
		||||
public:
 | 
			
		||||
    TreeNode * getTargetCopy(TreeNode * original, TreeNode * cloned, TreeNode * target) {
 | 
			
		||||
        if (original == nullptr) {
 | 
			
		||||
            return nullptr;
 | 
			
		||||
        }
 | 
			
		||||
        if (original == target) {
 | 
			
		||||
            return cloned;
 | 
			
		||||
        }
 | 
			
		||||
        TreeNode *left = getTargetCopy(original->left, cloned->left, target);
 | 
			
		||||
        if (left != nullptr) {
 | 
			
		||||
            return left;
 | 
			
		||||
        }
 | 
			
		||||
        return getTargetCopy(original->right, cloned->right, target);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user