I'm running into an issue when I try to check if an input integer array is empty. The error message just reads: cannot find symbol.
If the prices array is not empty, I want to be able to run the rest of the code.
If it is, I want it to return 0.
import java.util.ArrayList;
import java.util.Collections;
class Solution {
public int maxProfit(int[] prices) {
int i;
int j;
int profit;
int maxProfit = 0;
List<Integer> profitArray = new ArrayList<Integer>();
if (!prices.isEmpty()) {
for (i = 0; i < prices.length; i++) {
for (j = (i+1); j < ((prices.length)-1); j++) {
int diff = prices[j] - prices[i];
profitArray.add(diff);
}
}
profit = Collections.max(profitArray);
if (profit>0) {
maxProfit = profit;
}
maxProfit = 0;
return maxProfit;
}
return 0;
}
}