Skip to content

Commit a0ba7a9

Browse files
committed
solved: 485. Max Consecutive Ones
Signed-off-by: rajput-hemant <[email protected]>
1 parent 2970d03 commit a0ba7a9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
impl Solution {
2+
pub fn find_max_consecutive_ones(nums: Vec<i32>) -> i32 {
3+
let (mut count, mut max) = (0, 0);
4+
5+
for i in nums {
6+
if i == 1 {
7+
count += 1;
8+
} else {
9+
if count > max {
10+
max = count;
11+
}
12+
count = 0;
13+
}
14+
}
15+
16+
if count > max {
17+
max = count;
18+
}
19+
20+
max
21+
}
22+
}

0 commit comments

Comments
 (0)