diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md b/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md index 304d374be5a98..0503b372ae1e6 100644 --- a/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/README.md @@ -43,7 +43,7 @@ tags:
输入:derived = [1,1,0]
 输出:true
 解释:能够派生得到 [1,1,0] 的有效原始二进制数组是 [0,1,0] :
-derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1 
+derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1
 derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1
 derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0
 
@@ -164,4 +164,30 @@ function doesValidArrayExist(derived: number[]): boolean { + + +### Solution 2: Counting + + + +#### TypeScript + +```ts +function doesValidArrayExist(derived: number[]): boolean { + return derived.reduce((a, b) => a + b, 0) % 2 === 0; +} +``` + +#### JavaScript + +```js +function doesValidArrayExist(derived: number[]): boolean { + return derived.reduce((a, b) => a + b, 0) % 2 === 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..99101d56d5715 100644 --- a/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md @@ -43,7 +43,7 @@ tags: Input: derived = [1,1,0] Output: true Explanation: A valid original array that gives derived is [0,1,0]. -derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1 +derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1 derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1 derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0 @@ -165,4 +165,30 @@ function doesValidArrayExist(derived: number[]): boolean { + + +### Solution 2: Counting + + + +#### TypeScript + +```ts +function doesValidArrayExist(derived: number[]): boolean { + return derived.reduce((a, b) => a + b, 0) % 2 === 0; +} +``` + +#### JavaScript + +```js +function doesValidArrayExist(derived: number[]): boolean { + return derived.reduce((a, b) => a + b, 0) % 2 === 0; +} +``` + + + + + diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution2.js b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution2.js new file mode 100644 index 0000000000000..e8841b8a96be1 --- /dev/null +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution2.js @@ -0,0 +1,3 @@ +function doesValidArrayExist(derived: number[]): boolean { + return derived.reduce((a, b) => a + b, 0) % 2 === 0; +} diff --git a/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution2.ts b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution2.ts new file mode 100644 index 0000000000000..e8841b8a96be1 --- /dev/null +++ b/solution/2600-2699/2683.Neighboring Bitwise XOR/Solution2.ts @@ -0,0 +1,3 @@ +function doesValidArrayExist(derived: number[]): boolean { + return derived.reduce((a, b) => a + b, 0) % 2 === 0; +}