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

posted on 2017-04-19 10:55  Sempron2800+  阅读(105)  评论(0编辑  收藏  举报