- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1567.java
29 lines (28 loc) · 971 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
packagecom.fishercoder.solutions.secondthousand;
publicclass_1567 {
publicstaticclassSolution1 {
publicintgetMaxLen(int[] nums) {
intmax = 0;
for (inti = 0; i < nums.length; i++) {
if (nums.length - i <= max) {
returnmax;
}
if (nums[i] != 0) {
intnegatives = nums[i] > 0 ? 0 : 1;
max = Math.max(max, nums[i] > 0 ? 1 : 0);
for (intj = i + 1; j < nums.length; j++) {
if (nums[j] < 0) {
negatives++;
} elseif (nums[j] == 0) {
break;
}
if (negatives % 2 == 0) {
max = Math.max(max, j - i + 1);
}
}
}
}
returnmax;
}
}
}