C++ O(n) Dynamic programming
\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        \n        vector<int> pos_dp(nums.size(), 0);   \n        vector<int> neg_dp(nums.s
```\nclass Solution {\npublic:\n    int getMaxLen(vector<int>& nums) {\n        \n        vector<int> pos_dp(nums.size(), 0);   \n        vector<int> neg_dp(nums.size(), 0);   \n        if(nums[0] > 0) pos_dp[0] = 1;\n        if(nums[0] < 0) neg_dp[0] = 1;\n        int maxlen = pos_dp[0];\n        for(int i =1; i < nums.size(); i++) {            \n            if(nums[i] == 0) continue;\n            else if(nums[i] > 0){\n                pos_dp[i] = 1 + pos_dp[i-1];\n                neg_dp[i] = (neg_dp[i-1] == 0) ? 0 : 1 + neg_dp[i-1];\n            }\n            else {\n                // if(nums[i] < 0)\n                pos_dp[i] = (neg_dp[i-1] == 0) ? 0 : 1 + neg_dp[i-1];\n                neg_dp[i] = 1 + pos_dp[i-1];\n            }\n            \n            maxlen = maxlen > pos_dp[i] ? maxlen : pos_dp[i]; \n        }\n        return maxlen;\n    }\n};\n```
[]