2155. All Divisions With the Highest Score of a Binary Array

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2155

class Solution:
    def maxScoreIndices(self, nums: List[int]) -> List[int]:
        left, right = 0, sum(nums)
        mx = right
        res = [0]
        for i, num in enumerate(nums):
            if num == 0:
                left += 1
            else:
                right -= 1
            t = left + right
            if mx == t:
                res.append(i + 1)
            elif mx < t:
                mx = t
                res = [i + 1]
        return res