当前位置:网站首页>1734. arrangement after decoding XOR
1734. arrangement after decoding XOR
2022-06-11 07:01:00 【Not coriander】
Give you an array of integers perm , It's before n An arrangement of positive integers , And n It's a Odd number .
It's encrypted to another length of n - 1 Array of integers for encoded , Satisfy encoded[i] = perm[i] XOR perm[i + 1] . For example , If perm = [1,3,2] , that encoded = [2,1] .
Here you are. encoded Array , Please return to the original array perm . The question guarantees that the answer exists and is unique .
Example 1:
Input :encoded = [3,1]
Output :[1,2,3]
explain : If perm = [1,2,3] , that encoded = [1 XOR 2,2 XOR 3] = [3,1]
Example 2:
Input :encoded = [6,5,4,6]
Output :[2,4,1,5,3]
Tips :
3 <= n < 105
n Is odd .
encoded.length == n - 1
class Solution {
public:
vector<int> decode(vector<int>& encoded) {
vector<int>v;
//n Is odd
//len=n-1;
int len=encoded.size();
int n=len+1;
int first=0;
for(int i=1;i<=n;i++){
first^=i;
}
for(int i=1;i<len;i=i+2){
first^=encoded[i];
}
v.push_back(first);
for(int i=1;i<n;i++){
v.push_back(v[i-1]^encoded[i-1]);
}
return v;
}
};
边栏推荐
- Bat (batch processing) processing special symbols (exclamation point, percent sign), etc
- Object. Specific implementation and difference between create() and new
- 数学方法论的含义和研究意义
- 开源漫画服务器Mango
- JS implementation of graphic merging and sorting process [source code attached]
- 迅为干货 |瑞芯微RK3568开发板TFTP&NFS烧写(上)
- 【Matlab图像融合】粒子群优化自适应多光谱图像融合【含源码 004期】
- [MATLAB image encryption and decryption] chaotic sequence image encryption and decryption (including correlation test) [including GUI source code 1862]
- JVM from getting started to giving up 2: garbage collection
- Sohu employees encounter wage subsidy fraud. What is the difference between black property and gray property and how to trace the source?
猜你喜欢
![[Xunwei dry goods] opencv test of Godson 2k1000 development board](/img/94/312bb1f0d5e8d49506f659ad23cd3a.jpg)
[Xunwei dry goods] opencv test of Godson 2k1000 development board

Open source cartoon server mango
![Quick sorting of graphic array [with source code]](/img/ef/b1b98db5b16f0c4efc8d3c5247e8b0.jpg)
Quick sorting of graphic array [with source code]

JVM from getting started to abandoning 1: memory model

Nodejs database (Part 2)

Detailed explanation of mutual call between C language and Lua

Records how cookies are carried in cross domain requests

争议很大的问题
![Illustration of JS implementation from insertion sort to binary insertion sort [with source code]](/img/e5/1956af15712ac3e89302d7dd73f403.jpg)
Illustration of JS implementation from insertion sort to binary insertion sort [with source code]

Redux learning (III) -- using Redux saga, writing middleware functions, and splitting reducer files
随机推荐
webserver
Library management system 1- project approval
QT script document translation (I)
Object. Specific implementation and difference between create() and new
Duality-Gated Mutual Condition Network for RGBT Tracking
A highly controversial issue
Cross-Modal Pattern-Propagation for RGB-T Tracking
Leetcode-141. Linked List Cycle
Starting from scratch (IV) enemy aircraft flying out of the border disappear automatically
3.1 测试函数的命名规则
Cv2.rectangle() picture frame
【Matlab图像融合】粒子群优化自适应多光谱图像融合【含源码 004期】
**Count the characters with the largest number of words**
生物序列智能分析平台blog(1)
Post exam summary
Appclips & tips (continuous update)
模块化笔记
Summary of string processing skills II
常用问题排查工具和分析神器,值得收藏
Start the Nacos server of shell script