public static int search(int[] a, int target) {
        if (a == null || a.length == 0) {
            return 0;
        }

        int left = 0;
        int right = a.length - 1;
        while (left <= right) {
            int middle = (left + right) / 2;
            if (a[middle] == target) {
                return middle;
            }
            if (a[middle] < a[right]) {
                if (target > a[middle] && target <= a[right]) {
                    left = middle + 1;
                } else {
                    right = middle - 1;
                }
            } else {
                if (target >= a[left] && target < a[middle]) {
                    right = middle - 1;
                } else {
                    left = middle + 1;
                }
            }
        }
        return -1;
    }