comefrom: <awangdev>34. Find First and Last Position of Element in Sorted Array_2.java
code: 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 && mid - 1 >= 0 && nums[mid - 1] == target) end = mid;
                  else if (!isLeft && mid + 1 <= n - 1 && nums[mid + 1] == target) start = mid;
                  else return 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;
      }
masked: private int sample_funcname ( int [ ] var_0 , int var_1 , boolean var_2 ) {
    int var_3 = var_0 . length , var_4 = 0 , var_5 = var_3 - 1 ;
    while ( var_4 + 1 < var_5 ) {
      int var_6 = var_4 + ( var_5 - var_4 ) / 2 , var_7 = var_0 [ var_6 ] ;
      if ( var_7 == var_1 ) {
        if ( var_2 && var_6 - 1 >= 0 && var_0 [ var_6 - 1 ] == var_1 ) var_5 = var_6 ;
        else if ( ! var_2 && var_6 + 1 <= var_3 - 1 && var_0 [ var_6 + 1 ] == var_1 ) var_4 = var_6 ;
        else return var_6 ;
      }
      else if ( var_7 < var_1 ) var_4 = var_6 ;
      else var_5 = var_6 ;
    }
    if ( var_0 [ var_4 ] == var_1 && var_0 [ var_5 ] == var_1 ) return var_2 ? var_4 : var_5 ;
    if ( var_0 [ var_4 ] == var_1 ) return var_4 ;
    if ( var_0 [ var_5 ] == var_1 ) return var_5 ;
    return - 1 ;
  }
  