Skip to content
LC-2395 Easy LeetCode

2395. Find Subarrays With Equal Sum

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 66% Topics: Array, Hash Table
View full problem on LeetCode

Reading material

Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

# hash table
class Solution(object):
    def findSubarrays(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        lookup = set()
        for i in xrange(len(nums)-1):
            if nums[i]+nums[i+1] in lookup:
                return True
            lookup.add(nums[i]+nums[i+1])
        return False

Solution from kamyu104/LeetCode-Solutions · MIT