当前位置:网站首页>LetCode 1829. Maximum XOR value per query
LetCode 1829. Maximum XOR value per query
2022-07-01 03:52:00 【Daylight629】
1829. The maximum XOR value of each query
To give you one Orderly Array nums , It consists of n It's a nonnegative integer , I'll give you an integer at the same time maximumBit . You need to perform the following query n Time :
- Find a nonnegative integer
k < 2maximumBit, bringnums[0] XOR nums[1] XOR ... XOR nums[nums.length-1] XOR kResult Maximize .kIt's NoiThe answer to a query . - From the current array
numsDelete Last An element .
Please return an array answer , among answer[i] It's No i The result of a query .
Example 1:
Input :nums = [0,1,1,3], maximumBit = 2
Output :[0,3,2,3]
explain : The answers to the query are as follows :
First query :nums = [0,1,1,3],k = 0, because 0 XOR 1 XOR 1 XOR 3 XOR 0 = 3 .
The second query :nums = [0,1,1],k = 3, because 0 XOR 1 XOR 1 XOR 3 = 3 .
The third query :nums = [0,1],k = 2, because 0 XOR 1 XOR 2 = 3 .
The fourth query :nums = [0],k = 3, because 0 XOR 3 = 3 .
Example 2:
Input :nums = [2,3,4,7], maximumBit = 3
Output :[5,2,6,5]
explain : The answers to the query are as follows :
First query :nums = [2,3,4,7],k = 5, because 2 XOR 3 XOR 4 XOR 7 XOR 5 = 7.
The second query :nums = [2,3,4],k = 2, because 2 XOR 3 XOR 4 XOR 2 = 7 .
The third query :nums = [2,3],k = 6, because 2 XOR 3 XOR 6 = 7 .
The fourth query :nums = [2],k = 5, because 2 XOR 5 = 7 .
Example 3:
Input :nums = [0,1,2,2,5,7], maximumBit = 3
Output :[4,3,6,4,6,7]
Tips :
nums.length == n1 <= n <= 1051 <= maximumBit <= 200 <= nums[i] < 2maximumBitnumsThe number in has been pressed Ascending Arrange order well .
Two 、 Method 1
An operation
class Solution {
public int[] getMaximumXor(int[] nums, int maximumBit) {
int t = (1 << maximumBit)-1;
int n = nums.length;
int[] ans = new int[n];
ans[n-1] = nums[0] ^ t;
for(int i = 1; i < n; i++){
nums[i] ^= nums[i-1];
ans[n-1-i] = nums[i] ^ t;
}
return ans;
}
}
Complexity analysis
Time complexity :O(n).
Spatial complexity :O(1). The space required to store the returned answer is not included here .
边栏推荐
- 30. Concatenate substrings of all words
- Unexpected token o in JSON at position 1 ,JSON解析问题
- Valentine's Day is nothing.
- 30. 串联所有单词的子串
- 206.反转链表
- 报错:Plug-ins declaring extensions or extension points must set the singleton directive to true
- 283.移动零
- Why can't you find the corresponding function by clicking go to definiton (super easy has a diagram)
- 431. 将 N 叉树编码为二叉树 DFS
- Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
猜你喜欢

Future of NTF and trends in 2022

Appium自动化测试基础--补充:C/S架构和B/S架构说明

Sort linked list (merge sort)

使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
![[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle](/img/94/99090ea91082a385968e071ef3766c.png)
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
![[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation

Appium自动化测试基础 — APPium基本原理

Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination

Binary tree god level traversal: Morris traversal

【TA-霜狼_may-《百人计划》】1.3纹理的秘密
随机推荐
Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period
166. fractions to decimals
165. 比较版本号
[EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)
208. 实现 Trie (前缀树)
208. implement trie (prefix tree)
Database DDL (data definition language) knowledge points
[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
idea插件备份表
Libevent Library Learning
Web components series (VIII) -- custom component style settings
【TA-霜狼_may-《百人计划》】1.1 渲染流水线
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
“目标检测“+“视觉理解“实现对输入图像的理解
JMeter学习笔记2-图形界面简单介绍
Use of JMeter counters
72. 编辑距离
Develop industrial Internet with the technical advantages of small programs
Implement pow (x, n) function
AfxMessageBox和MessageBox的用法