본문 바로가기
python-algorithm

leetcode 2395. Find Subarrays With Equal Sum

by 무적김두칠 2023. 3. 13.

https://leetcode.com/problems/find-subarrays-with-equal-sum/description/

 

Find Subarrays With Equal Sum - LeetCode

Can you solve this real interview question? 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 tr

leetcode.com

 

1
2
3
4
5
6
7
8
9
10
class Solution:
    def findSubarrays(self, nums: List[int]) -> bool:
        sum_nums = []
        for i in range(1len(nums)):
            if (nums[i] + nums[i -1]) not in sum_nums:
                sum_nums.append((nums[i] + nums[i -1]))
            else:
                return True
        
        return False
cs
반응형

댓글