Skip to content

Commit 25a5644

Browse files
Add files via upload
1 parent 40fed65 commit 25a5644

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Searchinrotatedsortedarray.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
public class Searchinrotatedsortedarray {
2+
static int search(int nums[],int target){
3+
int a=0;
4+
int e=nums.length-1;
5+
while(a<=e){
6+
if(nums[a]==target){
7+
return a;
8+
}
9+
if(nums[e]==target){
10+
return e;
11+
}
12+
a++;
13+
e--;
14+
}
15+
return -1;
16+
}
17+
public static void main(String[]args){
18+
int nums[]={1,8,5,9,6};
19+
int target=6;
20+
21+
int a=Searchinrotatedsortedarray.search(nums, target);
22+
System.out.println(a);
23+
}
24+
}

0 commit comments

Comments
 (0)