public class RotationsNumbers {
public int main(String[] args) {
Solution ans= new Solution();
int[] arr= {5, 1,2, 3, 4};
System.out.println(ans.findKRotation(arr , 5));
return -1;
}
class Solution {
int findKRotation(int arr[], int n) {
// code here
int ans= findPivot(arr, 0 , n-1);
if( ans ==-1) return 0;
return ans+1;
}
int findPivot( int arr[], int start, int end){
int mid ;
while(start< end){
mid= start+ (end- start)/2;
if (mid < end && arr[mid]> arr[mid+1]){
return mid;
}
if ( mid > start && arr[mid ]< arr[mid-1]){
return mid-1;
}
if ( arr[ mid ] < arr[0]){
end= mid-1;
}else{
start= mid+1;
}
}
return -1;
}
}
}
Edit : Tried using static void main too .. still throwing error For the above code below error is getting thrown , what should i do?
Error: Main method must return a value of type void in class BinarySearch.SortedArray, please define the main method as: public static void main(String[] args)
Process finished with exit code 1