-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
48 lines (46 loc) · 1.12 KB
/
Copy pathsolution.java
File metadata and controls
48 lines (46 loc) · 1.12 KB
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
// 33. Search in Rotated Sorted Array
// https://leetcode.com/problems/search-in-rotated-sorted-array/
// Medium | Java | Accepted 2025-11-04
// Runtime 0 ms | Memory 43 MB
class Solution {
public int search(int[] nums, int target) {
int start = 0;
int end = nums.length-1;
int max = 0;
int minIndex = 0;
int[] normalArr = new int[nums.length];
while(start<end)
{
int mid = (start+end)/2;
if(nums[mid]>nums[end])
{
start = mid+1;
}
else
{
end = mid;
}
}
int rot = start;
start = 0;
end = nums.length-1;
while(start<=end)
{
int mid = (start+end)/2;
int realmid = (mid+rot)%nums.length;
if(nums[realmid]==target)
{
return realmid;
}
else if(nums[realmid]>target)
{
end = mid-1;
}
else
{
start = mid+1;
}
}
return -1;
}
}