Skip to content

Instantly share code, notes, and snippets.

View raviranjan3570's full-sized avatar
:octocat:
Focusing

Ravi Ranjan raviranjan3570

:octocat:
Focusing
View GitHub Profile
@raviranjan3570
raviranjan3570 / BinarySearch.java
Last active November 17, 2020 12:08
Algorithms for coding interview
class Solution {
public int search(int[] nums, int target) {
int left = 0;
int right = nums.length - 1;
while(left <= right){
int mid = left + (right - left) / 2;
// if target is found
if(nums[mid] == target){
return mid;