diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md b/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md index 304d374be5a98..02b76b1600900 100644 --- a/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md @@ -160,6 +160,38 @@ function doesValidArrayExist(derived: number[]): boolean { } ``` +#### Rust + +```rust +impl Solution { + pub fn does_valid_array_exist(derived: Vec) -> bool { + derived.iter().fold(0, |acc, &x| acc ^ x) == 0 + } +} +``` + +#### JavaScript + +```js +/** + * @param {number[]} derived + * @return {boolean} + */ +var doesValidArrayExist = function (derived) { + return derived.reduce((acc, x) => acc ^ x) === 0; +}; +``` + +#### C# + +```cs +public class Solution { + public bool DoesValidArrayExist(int[] derived) { + return derived.Aggregate(0, (acc, x) => acc ^ x) == 0; + } +} +``` + diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md b/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md index 9c28e18331126..cf70d03e6d899 100644 --- a/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md @@ -161,6 +161,38 @@ function doesValidArrayExist(derived: number[]): boolean { } ``` +#### Rust + +```rust +impl Solution { + pub fn does_valid_array_exist(derived: Vec) -> bool { + derived.iter().fold(0, |acc, &x| acc ^ x) == 0 + } +} +``` + +#### JavaScript + +```js +/** + * @param {number[]} derived + * @return {boolean} + */ +var doesValidArrayExist = function (derived) { + return derived.reduce((acc, x) => acc ^ x) === 0; +}; +``` + +#### C# + +```cs +public class Solution { + public bool DoesValidArrayExist(int[] derived) { + return derived.Aggregate(0, (acc, x) => acc ^ x) == 0; + } +} +``` + diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution.cs b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution.cs new file mode 100644 index 0000000000000..382d9e84a6871 --- /dev/null +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution.cs @@ -0,0 +1,5 @@ +public class Solution { + public bool DoesValidArrayExist(int[] derived) { + return derived.Aggregate(0, (acc, x) => acc ^ x) == 0; + } +} diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution.js b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution.js new file mode 100644 index 0000000000000..d7047c90136af --- /dev/null +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution.js @@ -0,0 +1,7 @@ +/** + * @param {number[]} derived + * @return {boolean} + */ +var doesValidArrayExist = function (derived) { + return derived.reduce((acc, x) => acc ^ x) === 0; +}; diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution.rs b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution.rs new file mode 100644 index 0000000000000..d7a8827fa7ffb --- /dev/null +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution.rs @@ -0,0 +1,5 @@ +impl Solution { + pub fn does_valid_array_exist(derived: Vec) -> bool { + derived.iter().fold(0, |acc, &x| acc ^ x) == 0 + } +}