1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| class Solution { public boolean search(int[] nums, int target) { if(nums.length == 0){ return false; } int frist = nums[0]; int last = nums[nums.length-1]; if(target == frist || target == last){ return true; }
if(target > frist){ for(int i = 1; i < nums.length; i++){ if(nums[i] == target){ return true; } if(nums[i] < nums[i-1]){ return false; } } }
if(target < last){ for(int i = nums.length - 2; i >= 0; i--){ if(nums[i] == target){ return true; } if(nums[i] > nums[i+1]){ return false; } } } return false; } }
|