1720. Decode XORed Array Easy

@problem@discussion
#Array#Bit Manipulation



1/**
2 * [1720] Decode XORed Array
3 *
4 * There is a hidden integer array arr that consists of n non-negative integers.
5 * It was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].
6 * You are given the encoded array. You are also given an integer first, that is the first element of arr, i.e. arr[0].
7 * Return the original array arr. It can be proved that the answer exists and is unique.
8 *  
9 * Example 1:
10 * 
11 * Input: encoded = [1,2,3], first = 1
12 * Output: [1,0,2,1]
13 * Explanation: If arr = [1,0,2,1], then first = 1 and encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]
14 * 
15 * Example 2:
16 * 
17 * Input: encoded = [6,2,7,3], first = 4
18 * Output: [4,2,0,7,4]
19 * 
20 *  
21 * Constraints:
22 * 
23 * 	2 <= n <= 10^4
24 * 	encoded.length == n - 1
25 * 	0 <= encoded[i] <= 10^5
26 * 	0 <= first <= 10^5
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/decode-xored-array/
32// discuss: https://leetcode.com/problems/decode-xored-array/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn decode(encoded: Vec<i32>, first: i32) -> Vec<i32> {
38        vec![]
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_1720() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.