Skip to content

Commit a255691

Browse files
authored
Create all-divisions-with-the-highest-score-of-a-binary-array.py
1 parent e1d66a7 commit a255691

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# prefix sum
5+
class Solution(object):
6+
def maxScoreIndices(self, nums):
7+
"""
8+
:type nums: List[int]
9+
:rtype: List[int]
10+
"""
11+
result = []
12+
mx = zeros = 0
13+
total = sum(nums)
14+
for i in xrange(len(nums)+1):
15+
zeros += ((nums[i-1] if i else 0) == 0)
16+
if zeros+(total-(i-zeros)) > mx:
17+
mx = zeros+(total-(i-zeros))
18+
result = []
19+
if zeros+(total-(i-zeros)) == mx:
20+
result.append(i)
21+
return result

0 commit comments

Comments
 (0)