Skip to content

Commit ddbe855

Browse files
committed
Add solution #1720
1 parent 1c8c71a commit ddbe855

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,498 LeetCode solutions in JavaScript
1+
# 1,499 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1325,6 +1325,7 @@
13251325
1717|[Maximum Score From Removing Substrings](./solutions/1717-maximum-score-from-removing-substrings.js)|Medium|
13261326
1718|[Construct the Lexicographically Largest Valid Sequence](./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js)|Medium|
13271327
1719|[Number Of Ways To Reconstruct A Tree](./solutions/1719-number-of-ways-to-reconstruct-a-tree.js)|Hard|
1328+
1720|[Decode XORed Array](./solutions/1720-decode-xored-array.js)|Easy|
13281329
1726|[Tuple with Same Product](./solutions/1726-tuple-with-same-product.js)|Medium|
13291330
1732|[Find the Highest Altitude](./solutions/1732-find-the-highest-altitude.js)|Easy|
13301331
1748|[Sum of Unique Elements](./solutions/1748-sum-of-unique-elements.js)|Easy|

solutions/1720-decode-xored-array.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 1720. Decode XORed Array
3+
* https://leetcode.com/problems/decode-xored-array/
4+
* Difficulty: Easy
5+
*
6+
* There is a hidden integer array arr that consists of n non-negative integers.
7+
*
8+
* It was encoded into another integer array encoded of length n - 1, such that
9+
* encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].
10+
*
11+
* You are given the encoded array. You are also given an integer first, that is the first
12+
* element of arr, i.e. arr[0].
13+
*
14+
* Return the original array arr. It can be proved that the answer exists and is unique.
15+
*/
16+
17+
/**
18+
* @param {number[]} encoded
19+
* @param {number} first
20+
* @return {number[]}
21+
*/
22+
var decode = function(encoded, first) {
23+
const result = [first];
24+
25+
for (let i = 0; i < encoded.length; i++) {
26+
result.push(result[i] ^ encoded[i]);
27+
}
28+
29+
return result;
30+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy