-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxProfit.java
40 lines (32 loc) · 838 Bytes
/
MaxProfit.java
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
public class MaxProfit {
private static int getMaxProfit(int[] nums,int n){
if(nums.length==0)
return 0;
int res[]=new int[n];
res[0]=nums[0];
int max=Integer.MIN_VALUE;
for(int j=1;j<n;j++){
int i=j-1;
int temp=nums[j];
while(i>=0){
if(nums[j]%nums[i]==0) {
temp += res[i];
break;
}
i--;
}
max=Math.max(max,temp);
res[j]=temp;
}
return max;
}
public static void main(String[] args) {
int[] arr={1,2,3,4,9,8};
int n=6;
int maxProfit = getMaxProfit(arr, n);
/* float[] arr3=new float[5];
Object f=arr3;
System.out.println(f[0]);
*/
}
}