国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LeetCode 33. Search in Rotated Sorted Array

2019-11-08 03:11:50
字體:
來源:轉載
供稿:網友

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).

You are given a target value to search. If found in the array return its index, otherwise return -1.

You may assume no duplicate exists in the array.

answer:

class Solution {public:    int search(vector<int>& nums, int target) {        if(nums.size() == 0) return -1;        int PRe;        if(nums[0] > target){            for(int i = nums.size() - 1; i > 0; i --){                if(nums[i] == target) return i;                if(nums[i] < nums[i - 1]) return -1;            }            return -1;        }        else if(nums[0] < target){            for(int i = 0; i <= nums.size() - 1; i ++){                if(nums[i] == target) return i;                if(nums[i] > nums[i + 1]) return -1;            }            return -1;        }        else return 0;    }};


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 唐海县| 谢通门县| 红桥区| 宣化县| 塔河县| 从化市| 玉山县| 靖远县| 项城市| 鹿泉市| 湖口县| 平顶山市| 永寿县| 旬邑县| 莱西市| 会昌县| 新源县| 梁平县| 固阳县| 龙里县| 象山县| 尼玛县| 阿拉尔市| 崇州市| 赞皇县| 苍梧县| 喜德县| 陕西省| 双鸭山市| 宣恩县| 斗六市| 佛坪县| 临沂市| 江安县| 武宣县| 灵川县| 息烽县| 静宁县| 环江| 永清县| 阿巴嘎旗|