LeetCode — Max Consecutive Ones

Given a binary array nums, return the maximum number of consecutive 1's in the array.

Example 1:

Input: nums = [1,1,0,1,1,1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.

Example 2:

Input: nums = [1,0,1,1,0,1]
Output: 2


  • 1 <= nums.length <= 105
  • nums[i] is either 0 or 1.





Dell Technologies — VxRail Software Engineer 👨‍💻

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Monitoring Temperature and Humidity Using InfluxDb and Grafana on Raspberry Pi

Privi Protocol, a progressive multi-chain DeFi platform is integrating with Matic Network !

A Configurable Third-Person Camera in Unity

Find size of an array using pointer hack in C/C++

5 Side Project Ideas for Web Developers

All you need to know about different data types in Python

Ingestion of tabular data using Azure

Tower of Hanoi

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Steven Lu

Steven Lu

Dell Technologies — VxRail Software Engineer 👨‍💻

More from Medium

LeetCode — First Bad Version

Binary Search Patterns

Data Alignment in C++ : Part 1

3rd Maximum in an Array