Skip to content

Commit af6e7fa

Browse files
aQuaaQua
aQua
authored and
aQua
committed
485 finish
1 parent 12eeb41 commit af6e7fa

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

Algorithms/0485.max-consecutive-ones/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Note:
1515
1. The length of input array is a positive integer and will not exceed `10,000`
1616

1717
## 解题思路
18-
18+
1. 标记
19+
2. 比较
20+
3. 记录
1921

2022
## 总结
2123

Algorithms/0485.max-consecutive-ones/max-consecutive-ones.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ package Problem0485
22

33
func findMaxConsecutiveOnes(nums []int) int {
44
max := 0
5-
temp := 0
6-
for i := 0; i < len(nums); i++ {
5+
6+
for i, j := 0, -1; i < len(nums); i++ {
77
if nums[i] == 0 {
8-
temp = 0
9-
}
10-
if nums[i] == 1 {
11-
temp++
12-
if max < temp {
13-
max = temp
8+
j = i
9+
} else {
10+
if max < i-j {
11+
max = i - j
1412
}
1513
}
1614
}
15+
1716
return max
1817
}

0 commit comments

Comments
 (0)