Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 485. Max Consecutive Ones

Posted on 2021-02-15 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int cnt = 0, ans = 0;
for (int num : nums) {
if (num == 1) {
++cnt;
} else {
ans = max(ans, cnt);
cnt = 0;
}
}
return max(ans, cnt);
}
};
# Array
LeetCode 41. First Missing Positive
LeetCode 487. Max Consecutive Ones II
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%