Skip to content
LC-2270 Medium LeetCode

2270. Number of Ways to Split Array

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 56% Topics: Array, Prefix Sum
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

# prefix sum
class Solution(object):
    def waysToSplitArray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        total = sum(nums)
        result = curr = 0
        for i in xrange(len(nums)-1):
            curr += nums[i]
            result += int(curr >= total-curr)
        return result

Solution from kamyu104/LeetCode-Solutions · MIT