[leetcode-485]Max Consecutive Ones

Easy等级,一次AC,效率都差不多,都是O(n),然后上一次AC代码:

class Solution {
public:
    int findMaxConsecutiveOnes(vector& nums) {
        if(nums.size()==0){
            return 0;
        }
        int maxx=0,countx=0,i;
        for(i=0;imaxx)maxx=countx;
                countx=0;
            }
            else{
                countx++;
            }

        }
        if(countx>maxx)maxx=countx;
        return maxx;
    }
};


你可能感兴趣的:(leetcode)