# [JAVA] Binary search method

I had the opportunity to write a 2-minute search, so I will write it as a memo.

# What is a 2-minute search?
The algorithm used when searching for data.
You can continue the search while narrowing down the range of sorted data.
A method for searching at high speed.

The 2-minute search is just an algorithm that searches while narrowing down the range by half from the entire array.
Fast.

`Sample.java`

```
int algorithm(int[] data, int target) {
int retrieve = -1;
int left = 0;
int right = data.length - 1;
while(left < right){
int mid = (left + right)/ 2;
if(data[mid] == target){
return mid + 1;
}else if(target < data[mid]){
return right = mid;
}else {
return left = mid + 1;
}
}
return retrieve;
}
```