原题题目
代码实现(首刷半看解半自解)
#define MAX 10001bool whetherdelect(int x,int to_deleteSize,int* to_delete)
{
int i;for(i=0;i<to_deleteSize;i++){
if(to_delete[i] == x)return true;}return false;
}struct TreeNode* visit(struct TreeNode* root,int* to_delete,int to_deleteSize,int* returnSize,struct TreeNode** ret)
{
if(root){
root->left = visit(root->left,to_delete,to_deleteSize,returnSize,ret);root->right = visit(root->right,to_delete,to_deleteSize,returnSize,ret);if(true == whetherdelect(root->val,to_deleteSize,to_delete)){
if(root->left)ret[(*returnSize)++] = root->left;if(root->right)ret[(*returnSize)++] = root->right;root = NULL;}return root;}return NULL;
}struct TreeNode** delNodes(struct TreeNode* root, int* to_delete, int to_deleteSize, int* returnSize){
*returnSize = 0;struct TreeNode** ret = (struct TreeNode **)malloc(sizeof(struct TreeNode*) * MAX);root = visit(root,to_delete,to_deleteSize,returnSize,ret);if(root)ret[(*returnSize)++] = root;return ret;
}