File tree Expand file tree Collapse file tree 5 files changed +81
-0
lines changed
solution/2600-2699/2683.Neighboring Bitwise XOR Expand file tree Collapse file tree 5 files changed +81
-0
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,38 @@ function doesValidArrayExist(derived: number[]): boolean {
160
160
}
161
161
```
162
162
163
+ #### Rust
164
+
165
+ ``` rust
166
+ impl Solution {
167
+ pub fn does_valid_array_exist (derived : Vec <i32 >) -> bool {
168
+ derived . iter (). fold (0 , | acc , & x | acc ^ x ) == 0
169
+ }
170
+ }
171
+ ```
172
+
173
+ #### JavaScript
174
+
175
+ ``` js
176
+ /**
177
+ * @param {number[]} derived
178
+ * @return {boolean}
179
+ */
180
+ var doesValidArrayExist = function (derived ) {
181
+ return derived .reduce ((acc , x ) => acc ^ x) === 0 ;
182
+ };
183
+ ```
184
+
185
+ #### C#
186
+
187
+ ``` cs
188
+ public class Solution {
189
+ public bool DoesValidArrayExist (int [] derived ) {
190
+ return derived .Aggregate (0 , (acc , x ) => acc ^ x ) == 0 ;
191
+ }
192
+ }
193
+ ```
194
+
163
195
<!-- tabs: end -->
164
196
165
197
<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -161,6 +161,38 @@ function doesValidArrayExist(derived: number[]): boolean {
161
161
}
162
162
```
163
163
164
+ #### Rust
165
+
166
+ ``` rust
167
+ impl Solution {
168
+ pub fn does_valid_array_exist (derived : Vec <i32 >) -> bool {
169
+ derived . iter (). fold (0 , | acc , & x | acc ^ x ) == 0
170
+ }
171
+ }
172
+ ```
173
+
174
+ #### JavaScript
175
+
176
+ ``` js
177
+ /**
178
+ * @param {number[]} derived
179
+ * @return {boolean}
180
+ */
181
+ var doesValidArrayExist = function (derived ) {
182
+ return derived .reduce ((acc , x ) => acc ^ x) === 0 ;
183
+ };
184
+ ```
185
+
186
+ #### C#
187
+
188
+ ``` cs
189
+ public class Solution {
190
+ public bool DoesValidArrayExist (int [] derived ) {
191
+ return derived .Aggregate (0 , (acc , x ) => acc ^ x ) == 0 ;
192
+ }
193
+ }
194
+ ```
195
+
164
196
<!-- tabs: end -->
165
197
166
198
<!-- solution: end -->
Original file line number Diff line number Diff line change
1
+ public class Solution {
2
+ public bool DoesValidArrayExist ( int [ ] derived ) {
3
+ return derived . Aggregate ( 0 , ( acc , x ) => acc ^ x ) == 0 ;
4
+ }
5
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } derived
3
+ * @return {boolean }
4
+ */
5
+ var doesValidArrayExist = function ( derived ) {
6
+ return derived . reduce ( ( acc , x ) => acc ^ x ) === 0 ;
7
+ } ;
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn does_valid_array_exist ( derived : Vec < i32 > ) -> bool {
3
+ derived. iter ( ) . fold ( 0 , |acc, & x| acc ^ x) == 0
4
+ }
5
+ }
You can’t perform that action at this time.
0 commit comments