1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 01:36:57 +02:00

java: add «2419. Longest Subarray With Maximum Bitwise AND»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-09-14 22:13:17 +02:00
parent fe390db878
commit 5449ec348a
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,25 @@
class Solution {
public int longestSubarray(int[] nums) {
int maximum = 0;
int longest = 0, current = 0;
for (var num : nums) {
if (maximum < num) {
maximum = num;
longest = current = 1;
continue;
}
if (num == maximum) {
++current;
} else {
current = 0;
}
longest = Math.max(longest, current);
}
return longest;
}
}