跟進“搜索旋轉排序數組”,假如有重複元素又將如何?
是否會影響運行時間複雜度?
如何影響?
爲何會影響?
寫出一個函數判斷給定的目標值是否出現在數組中。
給出[3,4,4,5,7,0,1,2]和target=4,返回 true
public class Solution {
/**
* param A : an integer ratated sorted array and duplicates are allowed
* param target : an integer to be search
* return : a boolean
*/
public boolean search(int[] A, int target) {
// write your code here
if(A.length==0||A==null){
return false;
}
for(int i=0;i<A.length;i++){
if(A[i]==target){
return true;
}
}
return false;
}
}