LeetCode(485)--最大连续1的个数
发布日期:2021-05-10 07:48:28 浏览次数:21 分类:精选文章

本文共 1861 字,大约阅读时间需要 6 分钟。

������������������������������������1���������

������������

������������������������������������������������1������������������������������������[1,1,0,1,1,1]���������������3������������������������������������1���������������������������

������������0���1���������������������������������������10000������

������

������������������������������������������������������������������������1���������������������������������������������������������

  • ���������������������count���max���������������������������1������������������������

  • ������������������������������������

    • ���������������������1���������count���������
    • ������������������������1������0���������������count���0���
    • ������������������������������������������������������������������������������������������������������������������������������������������������������������count���0���
  • ���������������0���������������������������������������count���max������������������max���������

  • ���������������������������max���������������������������1������������

    ������

    ������: [1,1,0,1,1,1]

    ������: 3

    ������: ���������������������������1������������1���1���������������1���1���1������������������������1������������3���

    ������������

    class Solution {
    public int findMaxConsecutiveOnes(int[] nums) {
    int count = 0;
    int max = 0;
    for (int index = 0; index < nums.length; index++) {
    if (nums[index] == 1) {
    count++;
    if (index < nums.length - 1) {
    continue;
    }
    }
    if (count > max) {
    max = count;
    }
    count = 0;
    }
    return max;
    }
    }

    ������

    ������������������������������������������������������������������������������������1���������������������������������������������O(n)���������������������O(1)������������������������������������

    上一篇:LeetCode(175)--组合两个表
    下一篇:HTML的input输入框变圆角后去掉边框的方法

    发表评论

    最新留言

    路过,博主的博客真漂亮。。
    [***.116.15.85]2025年04月27日 10时02分09秒