【LeetCode】数组-8(485)-01数组中找连续1的最大个数

思路:

  直接向后统计,遇到 0 就重置Max。

 1 class Solution {
 2     public int findMaxConsecutiveOnes(int[] nums) {
 3         int count = 0;
 4         int max = 0;
 5         for (int i = 0; i < nums.length; i++) {
 6             if (nums[i] == 1) {
 7                 count++;
 8                 if (max < count) 
 9                     max = count;
10             }else {
11                 count = 0;
12             }
13         }
14         return max;
15     }
16 }

 

posted @ 2017-08-20 10:56  菜鸟更要虚心学习  阅读(343)  评论(0编辑  收藏  举报