当前位置:网站首页>1720. 解码异或后的数组
1720. 解码异或后的数组
2022-07-20 22:24:00 【baixiaofei567】
先将first加入数组,然后遍历encoded,每一轮将res[i]和encoded[i]做异或的结果加入res。
class Solution {
public:
vector<int> decode(vector<int>& encoded, int first) {
//xor就是异或
//异或^,相同为0,不同为1,与运算&,全1为1,其余未0,|或运算,全0为0,其余为1
//根据first慢慢推,arr[i]^arr[i+1]=encoded[i]
//异或定理:a^b=c,a^b^b=a,所以用c代替a^b可以推出c^b=a,再用c^b代替a,可以推出c^b=a
//相当于a^b=c可以推导出c^a=b,c^b=a,直接反向异或就行了
vector<int> res;
res.push_back(first);
for(int i = 0; i < encoded.size(); ++i){
res.push_back(res[i] ^ encoded[i]);
}
return res;
}
};
边栏推荐
- It centralized purchase of Postal Savings Bank of China: servers, arrays, switches, routers, firewalls, etc
- BCG属性列表
- [program source code] information applet
- @RequestBody注解转对象中驼峰格式的参数无法接收到数据的问题解决方法
- 行人重识别reid
- c# winform 实际操作XML代码,包括创建、保存、查询、删除窗体演示
- [Baoyan] - interview precautions on the middle line of Baoyan summer camp
- Two hackers gained 2million illegal profits five days after they were released from prison: arrested
- 按Ctrl键会引发几次按键消息
- 经典自动化面试题
猜你喜欢
Got through! JIRA + Zadig realize demand and R & D process tracking
c# winform 实际操作XML代码,包括创建、保存、查询、删除窗体演示
《强化学习周刊》第54期:i-Sim2Real、GriddlyJS & 逆强化学习(IRL)最新应用
Responsive dream weaving template poultry breeding website
iptables详解
16个你要注意的SQL注入测试点
【保研】-- 保研夏令营中英语口语技巧问题
GAMES101图形学P11笔记(geometry2)
【保研】-- 保研夏令营中线上面试注意事项
GAMES101图形学P10笔记(geometry1)
随机推荐
[guaranteed research] - sort out and share the problems existing in the previous school reexamination interview
LeetCode 1260 二维网格迁移[数组] HERODING的LeetCode之路
前 3 名突然变了,揭秘 7 月编程语言最新排行榜
STM32串口屏学习
Ça marche! Jira + Zadig Implementation Requirements and R & D Process Tracking
Image of JZ27 binary tree
Got through! JIRA + Zadig realize demand and R & D process tracking
经典自动化面试题
Pit encountered by pl/sql
内网探测1-工作组信息收集&域内信息收集
中国 HCI 软件市场 TOP 10:华为、新华三、深信服、VMware、联想、SmartX、浪潮、青云、路坦力、曙光
JAX计算SeLU函数
股票开户网上办理的话安全吗股票开户去哪里
入门软件测试小知识点
RKE vs. rke2: compare two kubernetes distributions
有哪些高质量的自学网站?
iptables详解
「深度神经网络机器学习专栏」论文精选
STM32 serial port screen learning
BCG属性列表