C# Soln beats 88% RT


  • 0
    V

    A simple solution efficient on runtime but may not be the shortest code

    public class Solution {
        public int FindMaxConsecutiveOnes(int[] nums) {
            int max = 0;
            int current = 0;
            foreach(int i in nums)
            {
                if(i == 1) current++;
                else
                {
                    if(current > max) max = current;
                    current = 0;
                }
            }
            if(current > max) max = current;
            return max;
        }
    }
    

Log in to reply
 

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