首页 > 其他 > 详细

LeetCode - Search in Rotated Sorted Array II

时间:2015-12-06 11:19:05      阅读:136      评论:0      收藏:0      [点我收藏+]

题目:

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.

 

思路:

直接循环一遍查找

package array;

public class SearchInRotatedSortedArrayII {

    public boolean search(int[] nums, int target) {
        int len;
        if (nums == null || (len = nums.length) == 0) return false;
        for (int i = 0; i < len; ++i) 
            if (nums[i]==target)
                return true;
        return false;
    }
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int[] nums = { 3, 1, 1 };
        SearchInRotatedSortedArrayII s = new SearchInRotatedSortedArrayII();
        System.out.println(s.search(nums, 3));
    }

}

 

LeetCode - Search in Rotated Sorted Array II

原文:http://www.cnblogs.com/shuaiwhu/p/5023079.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!