search-in-rotated-sorted-array-ii

/ ** 
* for the Follow up "Search in the Sorted Rotated Array":
* Duplicates are allowed the What IF?
* Would Affect the this at The RUN-Time Complexity How and Why??
* A function to the Write the Determine IF IS A GIVEN target in at The Array .
*
* "Search in rotation sort the array," the follow-up operation:
* If allowed to repeat how to do?
* This affects the complexity of running it? How and why?
* Write a function to determine whether a given target in the array.
* /

java.util.Arrays Import; 

/ ** 
 * for the Follow up "Search in the Sorted Rotated Array": 
 * Duplicates are allowed the What IF? 
 * Would Affect the this at The RUN-Time Complexity How and Why?? 
 * A function to the Write the Determine IF . iS a GIVEN target in at the array 
 * 
 * "search in the rotation sort the array," the follow-up operation: 
 * If allowed to repeat how to do? 
 * This affects the complexity of running it? How and why? 
 * Write a function to determine whether a given target in the array. 
 * / 

Public class Main47 { 
    public static void main (String [] args) { 
        int [] = {0,2,3,4,6,7,1,2,3} A; 
        System.out.println (Search ( A,. 8)); 
        //Arrays.sort(A); 
        //System.out.println(Arrays.binarySearch(A,. 9) <0 to false: to true);? 
    }

    public static boolean search(int[] A, int target) {
        int len = A.length;
        for (int i=0;i<len;i++) {
            if (A[i] == target) {
                return true;
            }
        }

        return false;
    }
}

  

Guess you like

Origin www.cnblogs.com/strive-19970713/p/11344630.html