✅ beats 99% C++ code
Code\n\nclass Solution {\npublic:\n    Solution() {\n        ios_base::sync_with_stdio(false);\n        cin.tie(nullptr);\n    }\n    int getMaxLen(vector<int>&
# Code\n```\nclass Solution {\npublic:\n    Solution() {\n        ios_base::sync_with_stdio(false);\n        cin.tie(nullptr);\n    }\n    int getMaxLen(vector<int>& nums) {\n        int max_pos = nums[0] > 0;\n        int max_neg = nums[0] < 0;\n        int res = max_pos;\n        int n = nums.size();\n        for (int i = 1; i < n; i++) {\n            if (nums[i] > 0) {\n                max_pos++;\n                max_neg = max_neg > 0 ? max_neg + 1 : 0;\n            }\n            else if (nums[i] < 0) {\n                int t = max_pos;\n                max_pos = max_neg > 0 ? max_neg + 1 : 0;\n                max_neg = t > 0 ? t + 1 : 1;\n            }\n            else {\n                max_pos = max_neg = 0;\n            }\n            res = max(res, max_pos);\n        }\n        return res;\n    }\n};\n```\n![leetcode.jpeg](https://assets.leetcode.com/users/images/1b7c8f10-d814-4140-9f1e-6e719ec564d6_1675150827.4281044.jpeg)\n
['Array', 'Dynamic Programming', 'Greedy', 'C++']