java 485. Max Consecutive Ones.java

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 485. Max Consecutive Ones.java相关的知识,希望对你有一定的参考价值。

public class Solution {
    public int findMaxConsecutiveOnes(int[] nums) {
        if (nums == null || nums.length < 1) return 0;
        int res = 0;
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 1) {
                count++;
            } else {
                res = Math.max(res, count);
                count = 0;
            }
        }
        res = Math.max(res, count);
        return res;
    }
}

以上是关于java 485. Max Consecutive Ones.java的主要内容,如果未能解决你的问题,请参考以下文章

java 485. Max Consecutive Ones.java

java 485. Max Consecutive Ones.java

java 485. Max Consecutive Ones.java

java 485. Max Consecutive Ones.java

Leetcode刷题记录[java]——485 Max Consecutive Ones

485. Max Consecutive Ones