Simple C bynari search code 3ms only


  • 0
    M
    int bynari_search(int* nums, int left, int right)
    {
    	int res=0;
    	while (left < right)
    	{
    		if (nums[left] != nums[left + 1])
    			return nums[left];
    		else
    			left += 2;
    
    		if (nums[right] != nums[right - 1])
    			return nums[right];
    		else
    			right -= 2;
    	}
    	return -1;
    }
    
    int singleNonDuplicate(int* nums, int numsSize) 
    {
    	return bynari_search(nums, 0, numsSize - 1);
    }
    

  • 0
    This post is deleted!

Log in to reply
 

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