Skip to content

Commit 1f5f29d

Browse files
committed
feat: add solutions to lc problem: No.2395
No.2395.Find Subarrays With Equal Sum
1 parent e94c71b commit 1f5f29d

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

solution/2300-2399/2395.Find Subarrays With Equal Sum/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,39 @@ function findSubarrays(nums: number[]): boolean {
143143
}
144144
```
145145

146+
### **Rust**
147+
148+
```rust
149+
use std::collections::HashSet;
150+
impl Solution {
151+
pub fn find_subarrays(nums: Vec<i32>) -> bool {
152+
let n = nums.len();
153+
let mut set = HashSet::new();
154+
for i in 1..n {
155+
if !set.insert(nums[i - 1] + nums[i]) {
156+
return true;
157+
}
158+
}
159+
false
160+
}
161+
}
162+
```
163+
164+
### **C**
165+
166+
```c
167+
bool findSubarrays(int *nums, int numsSize) {
168+
for (int i = 1; i < numsSize - 1; i++) {
169+
for (int j = i + 1; j < numsSize; j++) {
170+
if (nums[i - 1] + nums[i] == nums[j - 1] + nums[j]) {
171+
return true;
172+
}
173+
}
174+
}
175+
return false;
176+
}
177+
```
178+
146179
### **...**
147180
148181
```

solution/2300-2399/2395.Find Subarrays With Equal Sum/README_EN.md

+33
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,39 @@ function findSubarrays(nums: number[]): boolean {
128128
}
129129
```
130130

131+
### **Rust**
132+
133+
```rust
134+
use std::collections::HashSet;
135+
impl Solution {
136+
pub fn find_subarrays(nums: Vec<i32>) -> bool {
137+
let n = nums.len();
138+
let mut set = HashSet::new();
139+
for i in 1..n {
140+
if !set.insert(nums[i - 1] + nums[i]) {
141+
return true;
142+
}
143+
}
144+
false
145+
}
146+
}
147+
```
148+
149+
### **C**
150+
151+
```c
152+
bool findSubarrays(int *nums, int numsSize) {
153+
for (int i = 1; i < numsSize - 1; i++) {
154+
for (int j = i + 1; j < numsSize; j++) {
155+
if (nums[i - 1] + nums[i] == nums[j - 1] + nums[j]) {
156+
return true;
157+
}
158+
}
159+
}
160+
return false;
161+
}
162+
```
163+
131164
### **...**
132165
133166
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bool findSubarrays(int *nums, int numsSize) {
2+
for (int i = 1; i < numsSize - 2; i++) {
3+
for (int j = i + 1; j < numsSize; j++) {
4+
if (nums[i - 1] + nums[i] == nums[j - 1] + nums[j]) {
5+
return true;
6+
}
7+
}
8+
}
9+
return false;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::collections::HashSet;
2+
impl Solution {
3+
pub fn find_subarrays(nums: Vec<i32>) -> bool {
4+
let n = nums.len();
5+
let mut set = HashSet::new();
6+
for i in 1..n {
7+
if !set.insert(nums[i - 1] + nums[i]) {
8+
return true;
9+
}
10+
}
11+
false
12+
}
13+
}

0 commit comments

Comments
 (0)