public class Solution { public int FindMaxConsecutiveOnes(int[] nums) { int Consecutive = 0; int max = 0; for (int i = 0; i < nums.Length; i++) { if (nums[i] == 1) { Consecutive++; if (i == nums.Length - 1) { if (Consecutive > max) { max = Consecutive; } } } else { if (Consecutive > max) { max = Consecutive; } Consecutive = 0; } } //Console.WriteLine(max.ToString()); return max; } }
https://leetcode.com/problems/max-consecutive-ones/#/description