File tree 4 files changed +89
-0
lines changed
solution/2300-2399/2395.Find Subarrays With Equal Sum
4 files changed +89
-0
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,39 @@ function findSubarrays(nums: number[]): boolean {
143
143
}
144
144
```
145
145
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
+
146
179
### **...**
147
180
148
181
```
Original file line number Diff line number Diff line change @@ -128,6 +128,39 @@ function findSubarrays(nums: number[]): boolean {
128
128
}
129
129
```
130
130
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
+
131
164
### **...**
132
165
133
166
```
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments