程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Search in Rotated Sorted Array

Search in Rotated Sorted Array

編輯:C++入門知識

Search in Rotated Sorted Array


Suppose a sorted array 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.

class Solution {
public:
    int search(int A[], int n, int target) {
        return bs(A,0,n-1,target);
    }
    int bs(int A[],int left,int right,int target){
        if(left




  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved