本文共 595 字,大约阅读时间需要 1 分钟。
题目原文:
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是有问题的。转载地址:http://hfomb.baihongyu.com/