您的位置:首页 > 其它

leetcode 98: Search in Rotated Sorted Array II

2013-03-04 11:45 447 查看
Search in Rotated Sorted Array IIApr
20 '12

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.

the time complexity is O(n). this is a example u can not do it in log(n); 11111111111111111113111, target 3. without scan all elements in the array, there is no chance you can find the 3.

public class Solution {
public boolean search(int[] A, int target) {
// Start typing your Java solution below
// DO NOT write main() function
// 8,9,10, 1,2,3,4,5,6,7   target 9
for(int i=0;i<A.length;i++) {
if(A[i]==target) return true;
}
return false;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: