LeetCode - 485. Max Consecutive Ones
Задача для самостоятельной работы.
Не смотри видео ниже, пока не попробуешь сам.
Код на языке Swift
func findMaxConsecutiveOnes(_ nums: [Int]) -> Int {
var maxCount = 0
var currentCount = 0
for num in nums {
if num == 1 {
currentCount += 1
} else {
maxCount = max(maxCount, currentCount)
currentCount = 0
}
}
maxCount = max(maxCount, currentCount)
return maxCount
}
course_intro
leetcode