GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Leetcode/33_SearchInRotateArray.cpp at master · ploverpang/Leetcode

Expand file tree

/

33_SearchInRotateArray.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
69 lines (66 loc) · 986 Bytes
/

33_SearchInRotateArray.cpp

Copy path

File metadata and controls

69 lines (66 loc) · 986 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
int search(vector<int>& nums, int target) {
int left = 0;
int right = nums.size()-1;
while(left <= right)
{
int middle = (left+right)/2;
if(target == nums[middle])
{
return middle;
}
if (nums[middle] < nums[left])
{
if (target < nums[middle])
{
right = middle-1;
}
else
{
if (target >= nums[left])
{
right = middle-1;
}
else
{
left = middle+1;
}
}
}
else
{
if (target > nums[middle])
{
left = middle+1;
}
else
{
if (target < nums[left])
{
left = middle+1;
}
else
{
right = middle-1;
}
}
}
}
return -1;
}
};
/*
int main()
{
int arr[] = {5,1,3};
vector<int> test(arr, arr+sizeof(arr)/sizeof(int));
Solution sln;
cout << sln.search(test, 5) << endl;
system("PAUSE");
return 0;
}
*/
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.