LC 898. Bitwise ORs of Subarrays
We have an array A
of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]]
(with i <= j
), we take the bitwise OR of all the elements in B
, obtaining a result A[i] | A[i+1] | ... | A[j]
.
Return the number of possible results. (Results that occur more than once are only counted once in the final answer.)
class Solution {
public:
int subarrayBitwiseORs(vector<int>& A) {
unordered_set<int> s;
set<int> t;
for(int i : A) {
set<int> r;
r.insert(i);
for(int j : t) r.insert(j | i);
t = r;
for(int j : t) s.insert(j);
}
return s.size();
}
};
LC 898. Bitwise ORs of Subarrays的更多相关文章
- [LeetCode] 898. Bitwise ORs of Subarrays 子数组按位或操作
We have an array A of non-negative integers. For every (contiguous) subarray B = [A[i], A[i+1], ..., ...
- 898. Bitwise ORs of Subarrays
We have an array A of non-negative integers. For every (contiguous) subarray B = [A[i], A[i+1], ..., ...
- 【LeetCode】898. Bitwise ORs of Subarrays 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 相似题目 参考资料 日期 题目地址:htt ...
- [Swift]LeetCode898. 子数组按位或操作 | Bitwise ORs of Subarrays
We have an array A of non-negative integers. For every (contiguous) subarray B = [A[i], A[i+1], ..., ...
- 子序列的按位或 Bitwise ORs of Subarrays
2018-09-23 19:05:20 问题描述: 问题求解: 显然的是暴力的遍历所有的区间是不可取的,因为这样的时间复杂度为n^2级别的,对于规模在50000左右的输入会TLE. 然而,最后的解答也 ...
- LeetCode编程训练 - 位运算(Bit Manipulation)
位运算基础 说到与(&).或(|).非(~).异或(^).位移等位运算,就得说到位运算的各种奇淫巧技,下面分运算符说明. 1. 与(&) 计算式 a&b,a.b各位中同为 1 ...
- 算法与数据结构基础 - 位运算(Bit Manipulation)
位运算基础 说到与(&).或(|).非(~).异或(^).位移等位运算,就得说到位运算的各种奇淫巧技,下面分运算符说明. 1. 与(&) 计算式 a&b,a.b各位中同为 1 ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
随机推荐
- css 布局方式
布局方式 1 布局:设置元素在网页中的排列方式及显示效果 2 分类: 1 标准流布局(文档流,普通流,静态流) 是默认的布局方式 特点:将元素按照书写顺序及元素类型,从上至下,从左至右排列 2 浮动布 ...
- linux命令详解——eval
shell中的eval 功能说明:重新运算求出参数的内容. 语 法:eval [参数] 补充说明:eval可读取一连串的参数,然后再依参数本身的特性来执行. 参 数:参数不限数目,彼此之间用分号分开. ...
- mesos-master启动失败,报错Failed to load unknown flag 'quorum.rpmsave'
[现象] mesos启动失败,查看mesos状态报错: [root@hps102 ~]# systemctl status mesos-master ● mesos-master.service - ...
- java - day008 - 接口,内部类
接口 作用: 结构设计工具,用来解耦合,需要有子类,隔离具体实现 接口是一个极端的抽象类 用 interface 代替 class 用 implements 代替 extends // 接口中所有东西 ...
- 用arduino的uno开发板为nano板子烧写bootloader
这篇文章,是为了记录下某宝上淘到的一个没有bootloader的nano开发板的历程(比较坑),自己搜索资料而记录的. 如果没有bootloader,板子就不能接收上传的程序,什么也干不了. 烧写bo ...
- Linux学习之八-配置FTP连接Linux服务器
配置ftp连接Linux服务器 通过配置ftp服务器,可以实现局域网内共享文件,甚至不同用户具有不同权限,需要的工具有Windows平台ftp客户端FileZilla(免费开源) 下载地址:https ...
- AppMain
@Controller@ComponentScan@Configuration@EnableScheduling@EnableAutoConfiguration(exclude={DataSource ...
- Ubuntu系统---C++之Eclipse 开始工程项目
Ubuntu系统---C++之Eclipse 开始工程项目 安装完Eclipse,那就像其它项目一样,先要测试一下是否能用. 一.测一个hello world例子二.利用OpenCV测试一个显示图片的 ...
- Window脚本学习笔记之BAT简介
本篇文章不是直接讲技术,而是对我自己学习这些年来的一番感触和简单的介绍,其间也穿插着一些基本的知识,若是学习技术者可跳过,亦不妨碍学习其他. BAT简介 BAT是Windows的批处理脚本,即以后缀“ ...
- go deep copy map
func deepCopyJSON(src map[string]interface{}, dest map[string]interface{}) error { if src == nil { r ...