Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion solution/2600-2699/2683.Neighboring Bitwise XOR/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tags:
<pre><strong>输入:</strong>derived = [1,1,0]
<strong>输出:</strong>true
<strong>解释:</strong>能够派生得到 [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
</pre>
Expand Down Expand Up @@ -164,4 +164,30 @@ function doesValidArrayExist(derived: number[]): boolean {

<!-- solution:end -->

<!-- solution:start -->

### Solution 2: Counting

<!-- tabs:start -->

#### 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;
}
```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
28 changes: 27 additions & 1 deletion solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tags:
<strong>Input:</strong> derived = [1,1,0]
<strong>Output:</strong> true
<strong>Explanation:</strong> A valid original array that gives derived is [0,1,0].
derived[0] = original[0] &oplus; original[1] = 0 &oplus; 1 = 1
derived[0] = original[0] &oplus; original[1] = 0 &oplus; 1 = 1
derived[1] = original[1] &oplus; original[2] = 1 &oplus; 0 = 1
derived[2] = original[2] &oplus; original[0] = 0 &oplus; 0 = 0
</pre>
Expand Down Expand Up @@ -165,4 +165,30 @@ function doesValidArrayExist(derived: number[]): boolean {

<!-- solution:end -->

<!-- solution:start -->

### Solution 2: Counting

<!-- tabs:start -->

#### 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;
}
```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
3 changes: 3 additions & 0 deletions solution/2600-2699/2683.Neighboring Bitwise XOR/Solution2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function doesValidArrayExist(derived: number[]): boolean {
return derived.reduce((a, b) => a + b, 0) % 2 === 0;
}
3 changes: 3 additions & 0 deletions solution/2600-2699/2683.Neighboring Bitwise XOR/Solution2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function doesValidArrayExist(derived: number[]): boolean {
return derived.reduce((a, b) => a + b, 0) % 2 === 0;
}
Loading