Skip to content

Commit c871b14

Browse files
committed
feat: add solutions to lc problem: No.2683
1 parent ca066db commit c871b14

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

solution/2600-2699/2683.Neighboring Bitwise XOR/README.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tags:
4343
<pre><strong>输入:</strong>derived = [1,1,0]
4444
<strong>输出:</strong>true
4545
<strong>解释:</strong>能够派生得到 [1,1,0] 的有效原始二进制数组是 [0,1,0] :
46-
derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1
46+
derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1
4747
derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1
4848
derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0
4949
</pre>
@@ -164,4 +164,30 @@ function doesValidArrayExist(derived: number[]): boolean {
164164

165165
<!-- solution:end -->
166166

167+
<!-- solution:start -->
168+
169+
### Solution 2: Counting
170+
171+
<!-- tabs:start -->
172+
173+
#### TypeScript
174+
175+
```ts
176+
function doesValidArrayExist(derived: number[]): boolean {
177+
return derived.reduce((a, b) => a + b, 0) % 2 === 0;
178+
}
179+
```
180+
181+
#### JavaScript
182+
183+
```js
184+
function doesValidArrayExist(derived: number[]): boolean {
185+
return derived.reduce((a, b) => a + b, 0) % 2 === 0;
186+
}
187+
```
188+
189+
<!-- tabs:end -->
190+
191+
<!-- solution:end -->
192+
167193
<!-- problem:end -->

solution/2600-2699/2683.Neighboring Bitwise XOR/README_EN.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tags:
4343
<strong>Input:</strong> derived = [1,1,0]
4444
<strong>Output:</strong> true
4545
<strong>Explanation:</strong> A valid original array that gives derived is [0,1,0].
46-
derived[0] = original[0] &oplus; original[1] = 0 &oplus; 1 = 1
46+
derived[0] = original[0] &oplus; original[1] = 0 &oplus; 1 = 1
4747
derived[1] = original[1] &oplus; original[2] = 1 &oplus; 0 = 1
4848
derived[2] = original[2] &oplus; original[0] = 0 &oplus; 0 = 0
4949
</pre>
@@ -165,4 +165,30 @@ function doesValidArrayExist(derived: number[]): boolean {
165165

166166
<!-- solution:end -->
167167

168+
<!-- solution:start -->
169+
170+
### Solution 2: Counting
171+
172+
<!-- tabs:start -->
173+
174+
#### TypeScript
175+
176+
```ts
177+
function doesValidArrayExist(derived: number[]): boolean {
178+
return derived.reduce((a, b) => a + b, 0) % 2 === 0;
179+
}
180+
```
181+
182+
#### JavaScript
183+
184+
```js
185+
function doesValidArrayExist(derived: number[]): boolean {
186+
return derived.reduce((a, b) => a + b, 0) % 2 === 0;
187+
}
188+
```
189+
190+
<!-- tabs:end -->
191+
192+
<!-- solution:end -->
193+
168194
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function doesValidArrayExist(derived: number[]): boolean {
2+
return derived.reduce((a, b) => a + b, 0) % 2 === 0;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function doesValidArrayExist(derived: number[]): boolean {
2+
return derived.reduce((a, b) => a + b, 0) % 2 === 0;
3+
}

0 commit comments

Comments
 (0)