forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_1567.java
29 lines (28 loc) · 956 Bytes
/
_1567.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.fishercoder.solutions;
public class _1567 {
public static class Solution1 {
public int getMaxLen(int[] nums) {
int max = 0;
for (int i = 0; i < nums.length; i++) {
if (nums.length - i <= max) {
return max;
}
if (nums[i] != 0) {
int negatives = nums[i] > 0 ? 0 : 1;
max = Math.max(max, nums[i] > 0 ? 1 : 0);
for (int j = i + 1; j < nums.length; j++) {
if (nums[j] < 0) {
negatives++;
} else if (nums[j] == 0) {
break;
}
if (negatives % 2 == 0) {
max = Math.max(max, j - i + 1);
}
}
}
}
return max;
}
}
}