81. Search in Rotated Sorted Array II
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]).
You are given a target value to search. If found in the array return true, otherwise return false.
Example 1:
Input: nums = [2,5,6,0,0,1,2], target = 0
Output: true
Example 2:
Input: nums = [2,5,6,0,0,1,2], target = 3 Output: false
题意:给定一个排好序的旋转后的数组和一个目标值,问目标值是否在数组中出现
代码如下:
/** * @param {number[]} nums * @param {number} target * @return {boolean} */ var search = function(nums, target) { for(var i=0;i<nums.length;i++){ if(nums[i]===target) return true; } return false; };
81. Search in Rotated Sorted Array II(js)
原文:https://www.cnblogs.com/xingguozhiming/p/10581897.html