题目:
Follow up for "Search in Rotated Sorted Array":
What if duplicates are allowed?
Would this affect the run-time complexity? How and why?
Write a function to determine if a given target is in the array.
思路:
直接循环一遍查找
packagearray;publicclassSearchInRotatedSortedArrayII {publicbooleansearch(int[] nums,inttarget) {intlen;if(nums ==null|| (len = nums.length) == 0)returnfalse;for(inti = 0; i < len; ++i)if(nums[i]==target)returntrue;returnfalse;
}publicstaticvoidmain(String[] args) {//TODO Auto-generated method stubint[] nums = { 3, 1, 1};
SearchInRotatedSortedArrayII s=newSearchInRotatedSortedArrayII();
System.out.PRintln(s.search(nums,3));
}
}