Skip to content

Commit 02dacdf

Browse files
committed
Time: 105 ms (58.77%), Space: 84.9 MB (34.21%) - LeetHub
1 parent cbf9764 commit 02dacdf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int longestSubarray(vector<int>& nums) {
4+
5+
int n = nums.size();
6+
int mx = *max_element(nums.begin(), nums.end());
7+
int ans = 0;
8+
for (int i = 0; i < n; ) {
9+
int cnt = 0;
10+
if (nums[i] == mx) {
11+
while (i < n && nums[i] == mx) {
12+
++cnt;
13+
++i;
14+
}
15+
} else ++i;
16+
ans = max(ans, cnt);
17+
}
18+
return ans;
19+
}
20+
};

0 commit comments

Comments
 (0)