Question: can you make a java method that gets the optimal buying and selling points from a given vector of integers? public static int [ ]
can you make a java method that gets the optimal buying and selling points from a given vector of integers?
public static int findMaximumSubarrayVector A int low, int high
if high low
return new intlow high, Agetlow;
else
int mid low high;
int left findMaximumSubarrayA low, mid;
int right findMaximumSubarrayA mid high;
int cross findMaxCrossingSubarrayA low, mid, high;
if left right && left cross
return left;
else if right left && right cross
return right;
else
return cross;
public static int findMaxCrossingSubarrayVector A int low, int mid, int high
int leftSum Integer.MINVALUE;
int sum ;
int maxLeft ;
for int i mid; i low; i
sum sum Ageti;
if sum leftSum
leftSum sum;
maxLeft i;
int rightSum Integer.MINVALUE;
sum ;
int maxRight ;
for int j mid ; j high; j
sum sum Agetj;
if sum rightSum
rightSum sum;
maxRight j;
return new intmaxLeft maxRight, leftSum rightSum;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
