public class Solution {
public static int maxProduct(int[] nums) {
int l = nums.length;
int max[] = new int[l];
int min[] = new int[l];
max[0] = nums[0];
min[0] = nums[0];
int product = max[0];
for (int i = 1; i < l; i++) {
max[i] = MaxinThree(nums[i], nums[i] * max[i  1], nums[i] * min[i  1]); // max in three
min[i] = MininThree(nums[i], nums[i] * max[i  1], nums[i] * min[i  1]); // min in three
if (max[i] > product)
product = max[i];
}
return product;
}
static int MaxinThree(int a, int b, int c) {
return (((a > b) ? a : b) > c) ? (a > b ? a : b) : c;
}
static int MininThree(int a, int b, int c) {
return (((a < b) ? a : b) < c) ? (a < b ? a : b) : c;
}
}
Java DP beats 90%,3ms. you can find something.


@justcodeit you can write
MaxinThree
andMininThree
in a much elegant/clear way. Like:max(max(a,b), c) min(min(a,b), c)