LintCode:搜索旋转排序数组 II

来源:互联网 发布:58网络销售怎么样 编辑:程序博客网 时间:2024/06/08 08:07

跟进“搜索旋转排序数组”,假如有重复元素又将如何?

是否会影响运行时间复杂度?

如何影响?

为何会影响?

写出一个函数判断给定的目标值是否出现在数组中。

您在真实的面试中是否遇到过这个题? 
Yes
样例
给出[3,4,4,5,7,0,1,2]和target=4,返回 true
标签 Expand
解题思路:
会有影响的,
http://www.code123.cc/docs/leetcode-
notes/binary_search/search_in_rotated_sorted_array.html
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        for(int i=0;i<A.length;i++){              if(target==A[i]){                   return true;              }         }         return false;          }}


0 0
原创粉丝点击