C# - one pass, no strings just iterate array - greedy - super simple


  • 1

    I don't think I've seen a simpler problem on this whole site.

        public int FindMaxConsecutiveOnes(int[] nums) 
        {
            int max = 0;
            int curr = 0;
            foreach (int x in nums)
            {
                curr = x == 0 ? 0 : curr + 1;
                max = curr > max ? curr : max;
            }
            return max;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.