Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit cbcfa18

Browse files
committed
Add solution #485
1 parent 12cafd0 commit cbcfa18

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

0485-max-consecutive-ones.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 485. Max Consecutive Ones
3+
* https://leetcode.com/problems/max-consecutive-ones/
4+
* Difficulty: Easy
5+
*
6+
* Given a binary array nums, return the maximum number of consecutive 1's in the array.
7+
*/
8+
9+
/**
10+
* @param {number[]} nums
11+
* @return {number}
12+
*/
13+
var findMaxConsecutiveOnes = function(nums) {
14+
let max = 0;
15+
for (let i = 0, count = 0; i < nums.length; i++) {
16+
count = nums[i] ? count + 1 : 0;
17+
max = Math.max(max, count);
18+
}
19+
return max;
20+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
461|[Hamming Distance](./0461-hamming-distance.js)|Easy|
196196
463|[Island Perimeter](./0463-island-perimeter.js)|Medium|
197197
476|[Number Complement](./0476-number-complement.js)|Easy|
198+
485|[Max Consecutive Ones](./0485-max-consecutive-ones.js)|Easy|
198199
491|[Non-decreasing Subsequences](./0491-non-decreasing-subsequences.js)|Medium|
199200
492|[Construct the Rectangle](./0492-construct-the-rectangle.js)|Easy|
200201
500|[Keyboard Row](./0500-keyboard-row.js)|Easy|

0 commit comments

Comments
 (0)