Accepted C Solution written in simple and neat code

  • 0
    int minDepth(struct TreeNode *root) {
    	if(NULL==root) return 0;
    	if(NULL==root->left && NULL==root->right)
    		return 1;
    	int l_d=minDepth(root->left);
    	int r_d=minDepth(root->right);
    	if(NULL!=root->left && NULL!=root->right){
    		return l_d<r_d? l_d+1 : r_d+1;
    	// one sub branch is null
    	return l_d>r_d? l_d+1 : r_d+1;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.