Middle-题目48:81. Search in Rotated Sorted Array II

原创 2016年05月31日 16:07:37

题目原文:
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.
题目大意:
对一个移位过后的升序数组(数组元素可能重复),判断一个数是否存在。
题目分析:
无脑找。O(n).
源码:(language:java)

public class Solution {
    public boolean search(int[] nums, int target) {
        for(int num:nums)
            if(num==target)
                return true;
        return false;
    }
}

成绩:
1ms,beats 21.80%,众数1ms,78.20%
Cmershen的碎碎念:
本题本应该考察的是二分搜索,可测试用例没有体现比无脑找的优势,而更是有21.8%的提交代码(可能是试图使用二分搜索)反而慢了。可能此题的test case是有问题的。

版权声明:完整版Leetcode题解请出门左转https://github.com/cmershen1/leetcode/tree/master/docs

相关文章推荐

leetcode_middle_86_81. Search in Rotated Sorted Array II

题意: 将一个升序数组,从中切断,将切断点后面的序列拼接到前面。注:切断点也可能在最后一个数字之后,即数组保持升序不变。 注意:数组中可能有重复数字。 分析: 这个数组长什么样呢?...

leetcode 81. Search in Rotated Sorted Array II-旋转数组|二分查找

原题链接:81. Search in Rotated Sorted Array II 【思路-Java、Python】 二分查找实现 本题采用二分法实现,但是比较挠头的是边界问题,而且元素有重复,...

[Leetcode] 81. Search in Rotated Sorted Array II 解题报告

题目: Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this aff...

【一天一道LeetCode】#81. Search in Rotated Sorted Array II

一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目...

Leetcode刷题记—— 81. Search in Rotated Sorted Array II(在翻转数组中查找2)

一、题目叙述: Follow up for "Search in Rotated Sorted A...

LeetCode OJ 81 Search in Rotated Sorted Array II

Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affec...

LeetCode 33,81. Search in Rotated Sorted Array i, ii

1. 题目描述33 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0...

[LeetCode]81. Search in Rotated Sorted Array II

81. Search in Rotated Sorted Array II Follow up for “Search in Rotated Sorted Array”: What if d...

81. Search in Rotated Sorted Array II

Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect ...

[leetcode 81] Search in Rotated Sorted Array II

题目描述: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand....
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)