JavaScript Dynamic Programming 12 lines
js\nfunction getMaxLen(nums) {\n  let max = 0, pos = 0, neg = 0;\n  for (let i = 0; i < nums.length; i++) {\n    if (nums[i] == 0) {\n      [pos, neg] = [0, 0];
```js\nfunction getMaxLen(nums) {\n  let max = 0, pos = 0, neg = 0;\n  for (let i = 0; i < nums.length; i++) {\n    if (nums[i] == 0) {\n      [pos, neg] = [0, 0];\n    } else if (nums[i] < 0) {\n      [pos, neg] = [neg > 0 ? neg+1 : 0, pos+1];\n    } else {\n      [pos, neg] = [pos+1, neg > 0 ? neg+1 : 0];\n    }\n    max = Math.max(max, pos);\n  }\n  return max;\n}\n```
[]