2419.cpp (408B)
1 class Solution { 2 public: 3 int longestSubarray(const vector<int> &nums) const { 4 const int maxi = *max_element(begin(nums), end(nums)); 5 6 int res = 0, cnt = 0; 7 for (const int n : nums) { 8 if (n == maxi) 9 cnt++; 10 else { 11 res = max(res, cnt); 12 cnt = 0; 13 } 14 } 15 16 return max(res, cnt); 17 } 18 };