码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode - Search in Rotated Sorted Array II

时间:2015-12-06 11:19:26      阅读:124      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!