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 说明:题目中含有$符号则为付费题目. 如 ...
随机推荐
- Java基础加强-代理
/*代理*//*代理的概念与作用*/ 代理过程架构 客户端Client原来直接调用的是Target目标类 使用代理后,现在让客户端不要调用Target,调用代理类Proxy,代理类Proxy和目标类T ...
- 阿里高级架构师教你使用Spring JMS处理消息事务源码案例
消费者在接收JMS异步消息的过程中会发生执行错误,这可能会导致信息的丢失.该源码展示如何使用本地事务解决这个问题.这种解决方案可能会导致在某些情况下消息的重复(例如,当它会将信息储存到数据库,然后监听 ...
- python3使用ConfigParser从配置文件中获取列表
使用python3使用ConfigParser从配置文件中获取列表 testConfig.py #!/usr/bin/env python # coding=utf- __author__ = 'St ...
- mysql打开报错2013解决办法
修改mysql配置文件 在[mysqld]下面设置skip-name-resolve 重启mysql from :https://www.jb51.net/article/52637.htm
- npm设置成淘宝镜像
1.淘宝 npm 网址 https://npm.taobao.org/ 2.修改 2.1 通过命令配置 2.1.1. 命令 npm config set registry https://regist ...
- 收藏!了解UART总线工作原理看这一篇就够了!
原文:玩转单片机 2019-08-24 16:50:29 越学到后面,基础知识更加不能忘记,温故而知新~~ 还记得当年的打印机,鼠标和调制解调器吗?他们都有巨大笨重的连接器和粗电缆,并且必须拧到你的电 ...
- 添加索引:BLOB/TEXT column 'xxx' used in key specification without a key length
问题 1. 将DataFrame数据保存到mysql后,添加索引出现错误提示: BLOB/TEXT column used in key specification without a key len ...
- pyecharts 开发文档
pyechart 新 版本 https://pyecharts.org/#/zh-cn/quickstart pyecharts 老版本 https://05x-docs.pyecharts.org/ ...
- Shell基本语法知识
Shell 就是一个命令解释器,他的作用就是解释执行用户输入的命令及程序等,用户每输入一条命令,Shell 就解释一条.这种从键盘一输入命令,就可以立即得到回应的对话方式,就称为交互的方式. 当命令或 ...
- luogu 2515
对于软件的依赖可以转化为图上点之间的边的关系发现对于一个强联通分量内的软件,一安则全安Tarjan缩点缩点后,从虚拟节点 0 向所有入度为 0 的点连边这样就构成了一棵树树形 dp$dp[i][j]$ ...