Max Consecutive Ones
给一个数组, 找出最长的连续的1. 经典dp算法.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public class Solution { public int findMaxConsecutiveOnes(int[] nums) { int max = 0; int cur = 0; for(int n : nums){ if(n == 0) cur = 0; else cur++; max = Math.max(max,cur); } return max; } } |