content: package lcof53_i_zai_pai_xu_shu_zu_zhong_cha_zhao_shu_zi;
  
  public class Solution {
  
      public int search(int[] nums, int target) {
          int floorIndex = floor(nums, target);
          if (floorIndex == -1) {
              return 0;
          }
          return ceil(nums, target) - floorIndex + 1;
      }
  
      private int floor(int[] nums, int target) {
          int left = 0, right = nums.length - 1;
          while (left <= right) {
              int mid = left + ((right - left) >> 1);
              if (nums[mid] == target) {
                  right = mid - 1;
              } else if (nums[mid] > target) {
                  right = mid - 1;
              } else {
                  left = mid + 1;
              }
          }
          if (left < nums.length && nums[left] == target) {
              return left;
          }
          return -1;
      }
  
      private int ceil(int[] nums, int target) {
          int left = 0, right = nums.length - 1;
          while (left <= right) {
              int mid = left + ((right - left) >> 1);
              if (nums[mid] == target) {
                  left = mid + 1;
              } else if (nums[mid] > target) {
                  right = mid - 1;
              } else {
                  left = mid + 1;
              }
          }
          if (right >= 0 && nums[right] == target) {
              return right;
          }
          return -1;
      }
  
  }