A Python Solution, with runtime O(n ^ 2)


  • 1
    K
        def canPartition(self, nums):
            all_sum = sum(nums)
            if all_sum % 2 == 1:
                return False
            sums = set()
            for num in nums:
                sums.update([i + num for i in sums])
                sums.add(num)
                if all_sum / 2 in sums:
                    return True
            return False
    

Log in to reply
 

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