首页 > 学院 > 开发设计 > 正文

LeetCode-SearchinRotatedSortedArrayII

2019-11-14 14:54:03
字体:
来源:转载
供稿:网友

题目:

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));    }}

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表