SHARE
TWEET

Untitled

a guest Aug 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static int binarySearch(int[] cost, int element, int left, int right){
  2.         if(left == right){
  3.             if(cost[left] != element) return -1;
  4.             else return left;
  5.         }
  6.  
  7.         int middle = (left+right)/2;
  8.         if(cost[middle] == element) return middle;
  9.         else if(cost[middle]<element)
  10.             return binarySearch(cost, element, middle+1, right);
  11.         else return binarySearch(cost, element, left, middle-1);
  12.        
  13.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top