LeetCode.485. Max Consecutive Ones

找出陣列中最長的連續 1
https://leetcode.com/problems/max-consecutive-ones/description/

class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        int result = 0,tmp=0;
        for(auto x: nums){
            if(x==1){
                tmp++;
            }else{
                tmp=0;
            }
            if(result<tmp){
                result = tmp;
            }
        }
        return result;
    }
};
















留言

這個網誌中的熱門文章

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header

經得起原始碼資安弱點掃描的程式設計習慣培養(三)_7.Cross Site Scripting(XSS)_Stored XSS_Reflected XSS All Clients

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題