public static int findPeak(int[] A) {
        // write your code here
		int len = A.length;
		if(A.length < 3){
			return -1;
		}
		if(A[2] < A[1]){
			return 1;
		}
		if(A[len - 3] < A[len -2]){
			return len - 2;
		}
		//the none of the above cases are OK
		int start = 1, end = len - 2;
		while(start < end){
			int mid = start + (end - start)/2;
			if(A[mid - 1] < A[mid] && A[mid] > A[mid+1])
				return mid;
			if(A[mid] < A[mid - 1]){
				//there must a peak in the left side
				end = mid;
				continue; 
				//!!!without this continue, the following code might execute.
				// leading wrong answer. 
			}
			if(A[mid] < A[mid + 1]){
				//there must a peak in the right side
				start = mid;
			}
		}
		return -1;
    }