scala version


  • 0
    M
      def findMaxConsecutiveOnes(nums: Array[Int]): Int = {
        var maxCount = 0
        var count = 0
        for (i <- nums) {
          if (i == 1) count += 1
          else count = 0
    
          if (count > maxCount) maxCount = count
        }
        maxCount
      }
    

Log in to reply
 

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