首页 > 编程语言 > 详细

leetCode 81.Search in Rotated Sorted Array II (旋转数组的搜索II) 解题思路和方法

时间:2015-07-22 14:40:40      阅读:181      评论: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.


思路:此题在解的时候,才发现Search in Rotated Sorted Array的时候想复杂了,其实只需要遍历搜索即可,线性时间。

代码如下:

public class Solution {
    public boolean search(int[] nums, int target) {
        for(int i = 0; i < nums.length; i++){
            if(nums[i] == target){
                return true;
            }
        }
        return false;
    }
}



版权声明:本文为博主原创文章,未经博主允许不得转载。

leetCode 81.Search in Rotated Sorted Array II (旋转数组的搜索II) 解题思路和方法

原文:http://blog.csdn.net/xygy8860/article/details/47002023

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