leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2419.cpp (408B)
0 class Solution {
1 public:
2 int longestSubarray(const vector<int> &nums) const {
3 const int maxi = *max_element(begin(nums), end(nums));
5 int res = 0, cnt = 0;
6 for (const int n : nums) {
7 if (n == maxi)
8 cnt++;
9 else {
10 res = max(res, cnt);
11 cnt = 0;
12 }
13 }
15 return max(res, cnt);
16 }
17 };