Java, O(n) time, O(1) space
\n    public int getMaxLen(int[] nums) {\n        // sum is used to count the number of negative numbers from zeroPosition to current index\n        int firstNe
```\n    public int getMaxLen(int[] nums) {\n        // sum is used to count the number of negative numbers from zeroPosition to current index\n        int firstNegative = -1, zeroPosition = -1, sum = 0, max = 0;\n        for(int i = 0;i < nums.length; i++){\n            if(nums[i] < 0){\n                sum++;\n\t\t\t\t// we only need to know index of first negative number\n                if(firstNegative == -1) firstNegative = i;\n            }\n\t\t\t// if current number is 0, we can\'t use any element from index 0 to i anymore, so update zeroPosition, and reset sum and firstNegative. If it is a game, we should refresh the game when we meet 0. \n            if(nums[i] == 0){\n                sum = 0;\n                firstNegative = -1;\n                zeroPosition = i;\n            }\n            else{\n\t\t\t    // consider index of zero\n                if(sum%2 == 0) max = Math.max(i - zeroPosition, max);\n\t\t\t\t// consider index of first negative number\n                else max = Math.max(i - firstNegative, max);   \n            }\n        }\n        return max;\n    }\n```
[]