clueless coding // TODO: be smarter

LeetCode Max Consecutive Ones: CPP Solution



TL;DR Code Solution


int findMaxConsecutiveOnes(vector<int>& nums) {
    if (nums.size() == 0) {
        return 0;
    }

    int current = 0;
    int result = 0;

    for (int i = 0; i < nums.size(); i++) {
        if (nums[i] == 1) {
            current++;
        }
        else {
            current = 0;
        }

        result = max(result, current);

    }

    return result;

}