Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add solutions to lc problem: No.2683 #3964

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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