<awangdev>34. Find First and Last Position of Element in Sorted Array_1.java
private int binarySearch(int[] nums, int target, boolean isLeft) {

        int n = nums.length, start = 0, end = n - 1;
        while (start + 1 < end) {
            int mid = start + (end - start) / 2, val = nums[mid];
            if (val == target) {
                if (isLeft) end = mid;
                else start = mid;
            } else if (val < target) start = mid;
            else end = mid;
        }
        if (nums[start] == target && nums[end] == target) return isLeft ? start : end;
        if (nums[start] == target) return start;
        if (nums[end] == target) return end;
        return -1;
    }
private int sample_funcname ( int [ ] var_0 , int var_1 , boolean var_3 ) {
  int var_5 = var_0 . length , var_7 = 0 , var_9 = var_5 - 1 ;
  while ( var_7 + 1 < var_9 ) {
    int var_11 = var_7 + ( var_9 - var_7 ) / 2 , var_12 = var_0 [ var_11 ] ;
    if ( var_12 == var_1 ) {
      if ( var_3 ) var_9 = var_11 ;
      else var_7 = var_11 ;
    }
    else if ( var_12 < var_1 ) var_7 = var_11 ;
    else var_9 = var_11 ;
  }
  if ( var_0 [ var_7 ] == var_1 && var_0 [ var_9 ] == var_1 ) return var_3 ? var_7 : var_9 ;
  if ( var_0 [ var_7 ] == var_1 ) return var_7 ;
  if ( var_0 [ var_9 ] == var_1 ) return var_9 ;
  return - 1 ;
}
