zoukankan      html  css  js  c++  java
  • 485. Max Consecutive Ones

    Given a binary array, find the maximum number of consecutive 1s in this array.

    Example 1:

    Input: [1,1,0,1,1,1]
    Output: 3
    Explanation: The first two digits or the last three digits are consecutive 1s.
        The maximum number of consecutive 1s is 3.


    求连续1的最大值

    C++(36ms):
    class Solution {
    public:
        int findMaxConsecutiveOnes(vector<int>& nums) {
            int ans = 0 ;
            int num = 0 ;
            for (int i : nums){
                if (i == 1)
                    num++ ;
                else
                    num = 0 ;
                ans = max(ans,num) ;
            }
            return ans ;
        }
    };
  • 相关阅读:
    CSS样式2
    页面布局
    CSS样式1
    HTML
    Document
    Document
    Document
    Document
    Document
    Document
  • 原文地址:https://www.cnblogs.com/mengchunchen/p/7116310.html
Copyright © 2011-2022 走看看