I was recently solving a question on LeetCode platform to delete a node from a Binary Search Tree, I wrote the given below iterative solution, I was wondering if it was a good practice to add a return statement within every if else block, that way the control would never reach the end of the function, however doing that did improve the time to pass all test cases. Any help appreciated ! /** * Definition for a binary tree node. * struct TreeNode { *     int val; *     TreeNode *left; *     TreeNode *right; *     TreeNode(int x) : val(x), left(NULL), right(NULL) {} * };*/class Solution {public:TreeNode* deleteNode(TreeNode* root, int key) {    if(!root)        return NULL;    if(root->val==key && !root->left && !root->right)        return NULL;    TreeNode* root1=root;    TreeNode* parent=root;    while(root1 && root1->val!=key){        parent=root1;        if(key<root1->val)            root1=root1->left;        else            root1=root1->right;    }    TreeNode* delNode=root1;    if(!root1)        return root;    if(!root1->left && !root1->right){        if(parent->left==root1)            parent->left=NULL;        else            parent->right=NULL;        return root;    }    else if(root1->right){        parent=root1;        root1=root1->right;        while(root1->left){            parent=root1;            root1=root1->left;        }        delNode->val=root1->val;        if(parent==delNode)            parent->right=root1->right;        else            parent->left=root1->right;        return root;    }    else{        if(parent==delNode)            root=root->left;        else             if(parent->left==delNode)            parent->left=delNode->left;        else            parent->right=delNode->left;        return root;    }    return root;}};
Delete a node from a Binary Search Tree
c++;performance;tree