LeetCode 421. 数组中两个数的最大异或值(Maximum XOR of Two Numbers in an Array) 71
421. 数组中两个数的最大异或值
421. Maximum XOR of Two Numbers in an Array
题目描述
给定一个非空数组,数组中元素为 a0, a1, a2, … , an-1,其中 0 ≤ ai < 231。
找到 ai 和 aj 最大的异或 (XOR) 运算结果,其中 0 ≤ i,j < n。
你能在 O(n) 的时间解决这个问题吗?
每日一算法2019/7/13Day 71LeetCode421. Maximum XOR of Two Numbers in an Array
示例:
输出: 28
解释: 最大的结果是 5 ^ 25 = 28。
Java 实现
class Solution {
public int findMaximumXOR(int[] nums) {
int max = 0;
for (int i = 0; i < nums.length - 1; i++) {
for (int j = i + 1; j < nums.length; j++) {
if ((nums[i] ^ nums[j]) > max) {
max = nums[i] ^ nums[j];
}
}
}
return max;
}
}
参考资料
- https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/
- https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/
LeetCode 421. 数组中两个数的最大异或值(Maximum XOR of Two Numbers in an Array) 71的更多相关文章
- [Swift]LeetCode421. 数组中两个数的最大异或值 | Maximum XOR of Two Numbers in an Array
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- Java实现 LeetCode 421 数组中两个数的最大异或值
421. 数组中两个数的最大异或值 给定一个非空数组,数组中元素为 a0, a1, a2, - , an-1,其中 0 ≤ ai < 231 . 找到 ai 和aj 最大的异或 (XOR) 运算 ...
- Leetcode 421.数组中两数的最大异或值
数组中两数的最大异或值 给定一个非空数组,数组中元素为 a0, a1, a2, … , an-1,其中 0 ≤ ai < 231 . 找到 ai 和aj 最大的异或 (XOR) 运算结果,其中0 ...
- 421 Maximum XOR of Two Numbers in an Array 数组中两个数的最大异或值
给定一个非空数组,数组中元素为 a0, a1, a2, … , an-1,其中 0 ≤ ai < 231 .找到 ai 和aj 最大的异或 (XOR) 运算结果,其中0 ≤ i, j < ...
- LeetCode 数组中两个数的最大异或值
题目链接:https://leetcode-cn.com/problems/maximum-xor-of-two-numbers-in-an-array/ 题目大意: 略. 分析: 字典树 + 贪心. ...
- leetcode-421-数组中两个数的最大异或值*(前缀树)
题目描述: 方法一: class Solution: def findMaximumXOR(self, nums: List[int]) -> int: root = TreeNode(-1) ...
- 2016网易实习生编程题:数组中两个数的和等于sum
题目 找出数组中两个数的和等于sum的这两个数 解题 这个题目做过很多次了,利用HashMap,key为 sum-A[i] value为 i 当 加入HashMap时候A[i] 已经存在map中,ge ...
- leetcode 421.Maximum XOR of Two Numbers in an Array
题目中给定若干个数,然后任意选定两个数使得其异或值最大. 先利用样例中的: 3 10 5 25 2 8 这些数转换为二进制来看的话那么是先找到最高位的1然后与数组中其他的数相与后的数值保存到set中去 ...
- [LeetCode] 421. Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
随机推荐
- 最小球覆盖——模拟退火&&三分套三分套三分
题目 给出 $N(1 \leq N \leq 100)$ 个点的坐标 $x_i,y_i,z_i$($-100000 \leq x_i,y_i,z_i \leq 100000$),求包围全部点的最小的球 ...
- OpenCV 学习笔记(5) 使用opencv打开笔记本摄像头
#include "stdafx.h" #include <opencv2\opencv.hpp> #include <iostream> #include ...
- [教程]Ubuntu16.04安装texstudio
[教程]Ubuntu16.04安装texstudio step 1 首先要下载texlive. 不会的戳这里 然后直接终端命令 sudo apt-get install texstudio step ...
- Python爬虫selenium中get_cookies()和add_cookie()的用法
在用selenium爬取网页的时候,有时候需要登陆,这时候用selenium获取cookie和携带cookie是很方便的,获取cookie可以通过内置的函数get_cookies(),它得到的是一组c ...
- 全部文章> Maven
Maven 原 Maven中<resources>标签详解 &nbsp;&nbsp;&nbsp;&nbsp;& ...
- .NET 爬虫总结
前言 技术本身并无罪,罪恶本质在于人心,好比厨师手中的菜刀用来创造美味佳肴,而杀手手上的刀却用来创造无限的罪恶. 环境 win7 IIS 6.0 SQLserver2012 .NET 4.0 win ...
- 如何高效的阅读uni-app框架?(建议收藏)
作者 | Jeskson来源 | 达达前端小酒馆 uni-app的框架,配置:page.json,manifest.json,package.json,vue.config.js.脚本,应用程序,ma ...
- Java解决java.io.FileNotFoundException: E:\work\work (拒绝访问。)
一.问题 在使用FileInputStream或FileOutputStream时会遇到如下问题1和问题2. 问题1: java.io.FileNotFoundException: .\xxx\xxx ...
- eclipse Target runtime com.genuitec.runtime.generic.jee50 is not defined
1.情景展示 报错信息如下: 2.原因分析 使用eclipse导入myeclipse时,唯独这个报错信息改不了. 需要通过修改这个项目的配置文件才行. 3.解决方案 第一步:切换到导航视图: 第二 ...
- exception java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
1.情景展示 Java 报错信息如下: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 2.原因分析 首先,这是越界异常,但不是数组越 ...