Follow up for "Search in Rotated Sorted Array":What ifduplicatesare 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;}}
版权声明:本文为博主原创文章,,未经博主允许不得转载。
也有伤心的,既有令人兴奋的,也有令人灰心的,