2395. Find Subarrays With Equal Sum Easy
1/**
2 * [2395] Find Subarrays With Equal Sum
3 *
4 * 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.
5 * Return true if these subarrays exist, and false otherwise.
6 * A subarray is a contiguous non-empty sequence of elements within an array.
7 *
8 * Example 1:
9 *
10 * Input: nums = [4,2,4]
11 * Output: true
12 * Explanation: The subarrays with elements [4,2] and [2,4] have the same sum of 6.
13 *
14 * Example 2:
15 *
16 * Input: nums = [1,2,3,4,5]
17 * Output: false
18 * Explanation: No two subarrays of size 2 have the same sum.
19 *
20 * Example 3:
21 *
22 * Input: nums = [0,0,0]
23 * Output: true
24 * Explanation: The subarrays [nums[0],nums[1]] and [nums[1],nums[2]] have the same sum of 0.
25 * Note that even though the subarrays have the same content, the two subarrays are considered different because they are in different positions in the original array.
26 *
27 *
28 * Constraints:
29 *
30 * 2 <= nums.length <= 1000
31 * -10^9 <= nums[i] <= 10^9
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/find-subarrays-with-equal-sum/
37// discuss: https://leetcode.com/problems/find-subarrays-with-equal-sum/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn find_subarrays(nums: Vec<i32>) -> bool {
43 false
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_2395() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.