0ms C solution recursive simple


  • 0
    C
    int findMinIndex(int* nums, int left, int right)
    {
    	int leftMin = INT_MAX;
    	int rightMin = INT_MAX;
    
    	if (right-left <= 0)
    	{
    		return nums[left];
    	}
    	else if (right-left == 1)
    	{
    		return (nums[right] < nums[left]? nums[right]: nums[left]);
    	}
    
    	leftMin = findMinIndex(nums, left, (left+right)/2);
    	rightMin = findMinIndex(nums, ((left+right)/2)+1, right);
    
    	return (leftMin < rightMin? leftMin : rightMin);
    }
    
    int findMin(int* nums, int numsSize) {
    
    	return findMinIndex(nums, 0, numsSize-1);
    }

Log in to reply
 

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