Binary search with only sorted elements. At first we need to ensure that the array we're searching element is sorted in ascending or descending order
public static boolean findElement(int[] nums, int target)
{
int lengthOfArray = nums.length;
int left = 0, right = lengthOfArray-1;
while(left <= right){
int mid = left + (right - left)/2;
if(nums[mid] == target){
return true;
}
if(nums[mid] > target){
right = mid-1;
}
else{
left = mid + 1;
}
}
return false;
}