public class Solution {
public int LongestSubarray(int[] nums) {
int ans = 1, ansMaxVal = nums[0];
int maxVal = nums[0], len = ans;
void Judge() {
if(ansMaxVal == maxVal){
ans = Math.Max(ans, len);
}else if(ansMaxVal < maxVal) {
ansMaxVal = maxVal;
ans = len;
}
}
for(int ind = 1; ind < nums.Length; ind++) {
if(maxVal == nums[ind]) {
len++;
}else {
// maxVal < nums[ind]
Judge();
len = 1;
maxVal = nums[ind];
}
}
Judge();
return ans;
}
}
2419. 按位与最大的最长子数组
最新推荐文章于 2024-08-18 17:01:18 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)