int b = 0; int e = size; int ret = nums[0]; while (b < e) { int tb = b; while (b < e && nums[b] != 0) ++b; if (b - tb <= 1) { ret = max(ret, nums[tb]); if (b < e) ret = max(ret, nums[b]); b += 1; continue; }
int sum = 1; int tb2 = tb; while (tb2 < b) sum *= nums[tb2++];
if (sum < 0) { int sumneg1 = 1; tb2 = tb; while (tb2 < b) { sumneg1 *= nums[tb2]; if (nums[tb2] < 0) break; ++tb2; } int sum1 = sumneg1 / nums[tb2] == 1 ? sumneg1 : sumneg1 / nums[tb2];
int sumneg2 = 1; tb2 = b - 1; while (tb2 >= tb) { sumneg2 *= nums[tb2]; if (nums[tb2] < 0) break; --tb2; } int sum2 = sumneg2 / nums[tb2] == 1 ? sumneg2 : sumneg2 / nums[tb2];
sum /= max(sumneg1, sumneg2); sum = max(sum, sum1); sum = max(sum, sum2); }