1734. Decode XORed Permutation Medium

@problem@discussion
#Array#Bit Manipulation



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


Back
© 2025 bowen.ge All Rights Reserved.