-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3719.java
More file actions
26 lines (23 loc) · 700 Bytes
/
Q3719.java
File metadata and controls
26 lines (23 loc) · 700 Bytes
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
class Solution {
private static int[] seen = new int[100001];
private static int leet = 0;
public int longestBalanced(int[] nums) {
leet++;
int n = nums.length;
int res = 0;
for (int i = 0; i < n && n - i > res; i++) {
int[] A = new int[2];
int marker = (leet << 16) | (i + 1);
for (int j = i; j < n; j++) {
int val = nums[j];
if (seen[val] != marker) {
seen[val] = marker;
A[val & 1]++;
}
if (A[0] == A[1])
res = Math.max(res, j - i + 1);
}
}
return res;
}
}