国产探花免费观看_亚洲丰满少妇自慰呻吟_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;    }};


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 侯马市| 桑植县| 石嘴山市| 呈贡县| 怀远县| 叙永县| 沅江市| 颍上县| 仪征市| 黄浦区| 南投市| 托里县| 利辛县| 尼木县| 栾川县| 伽师县| 怀宁县| 中卫市| 伊川县| 正镶白旗| 阜宁县| 垫江县| 尚义县| 寻乌县| 女性| 凤庆县| 新邵县| 铜山县| 饶河县| 威信县| 宝鸡市| 广河县| 绥德县| 育儿| 遂溪县| 枝江市| 钦州市| 乌兰察布市| 农安县| 昌乐县| 天门市|