Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s.The maximum number of consecutive 1s is 3.
public int findMaxConsecutiveOnes(int[] nums) { int max_ones = 0; for (int i = 0; i < nums.length; i++) {
int cur_max = 0; while (i < nums.length && nums[i] == 1) { cur_max++; i++; }
max_ones = Math.max(cur_max, max_ones); } return max_ones; }
leetcode485. Max Consecutive Ones
最新推荐文章于 2024-07-21 08:37:44 发布