Python, convert the problem into two find mid point problems


  • 0
    G
    class Solution(object):
        def splitArray(self, nums):
            """
            :type nums: List[int]
            :rtype: bool
            """
            if len(nums)<7:
                return False
                
            for mid in range(3,len(nums)-3):
                left = self.findmid(nums,0,mid-1)
                right = self.findmid(nums,mid+1,len(nums)-1)
                if left and right and left.intersection(right):
                    return True
            return False
            
        def findmid(self, nums,s,e):
            output =set()
            l=[0]*(e-s+1)
            l[0] = nums[s]
            for i in range(1,e-s+1):
                l[i] = l[i-1]+nums[s+i]
            for i in range(0,e-s-1):
                if l[i]==l[-1]-l[i+1]:
                    output.add(l[i])
                    
            return output

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.