mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 18:07:32 +01:00
26 lines
421 B
Java
26 lines
421 B
Java
|
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;
|
||
|
}
|
||
|
}
|