2395 Find Subarrays With Equal Sum
Given a 0-indexed integer array nums
, determine whether there exist two subarrays of length 2
with equal sum. Note that the two subarrays must begin at different indices.
Return true
if these subarrays exist, and false
otherwise.
A subarray is a contiguous non-empty sequence of elements within an array.
Example 1:
Example 2:
Example 3:
Constraints:
2 <= nums.length <= 1000
-109 <= nums[i] <= 109
这题主要是1477 Find Two Non-overlapping Sub-arrays Each With Target Sum原题做不通,然后点开相关题目过来看看有啥灵感才做的。这里因为规定了长度为2,而且subarray可以overlap。所以直接loop一圈,两两算一个和,用set查重。找到了就return。T:O(n), S:O(n)
Last updated