public int[] searchForRange(int[] num, int target){
    int[] res = new int[2];
    if (num.length == 0){
      res[0] = -1;
      res[1] = -1;
      return res;
    }
    
    /* search for the start index. */
    int start = -1;
    if (num[0] == target){
      start = 0;
    } else {
      for (int i = 1; i < num.length - 1; i++) {
        if (num[i] != target && num[i + 1] == target) {
          start = i + 1;
          break;
        }
      }
    }
    
    /* search for the end index. */
    int end = -1;
    if (num[num.length - 1] == target){
      end = num.length - 1;
    } else {
      for (int i = 0; i < num.length - 1; i++) {
        if (num[i] == target && num[i + 1] != target) {
          end = i;
          break;
        }
      }
    }
    
    res[0] = start;
    res[1] = end;
    
    return res;
  }