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基础加强-jdk1.5的一些新特性
JDK 5.0 特性 1.静态导入(import static 语句导入一个类中的某个静态方法或所有静态方法) 如: import static java.lang.Math.*; 2.可变参数 1. ...
- 1249: 人见人爱A^B
题目描述 求A^B的最后三位数表示的整数. 说明:A^B的含义是“A的B次方” 输入 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果 ...
- 后台向前台响应的json数据格式的一些问题
最近在写后台向前台easyUI页面发送数据时遇到的一些报错. 首先easyUI内部封装了许多的方法和对象,以至于很多参数都不清楚,需要查询,其次easyUI也是有内置ajax所以从后台响应回来的数据一 ...
- Android 启动流程分析
原文:https://www.jianshu.com/p/a5532ecc8377 作者曾经在高通的Android性能组工作,主要工作是优化Android Application的启动时间. APP基 ...
- 关于Python的第一行语句
通常在脚本语言的第一行会看到#!/usr/bin/env python 与 #!/usr/bin/python其中之一,这两句话的目的都是指出你的python文件用什么可执行程序去运行它. #!/us ...
- 中国大学MOOC课程信息之数据分析可视化二
版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/82318571 - 写在前面 本篇博客继续对中国大学MOOC ...
- 【转】解决高版本springboot对Velocity不支持
https://blog.csdn.net/sinat_31270499/article/details/82283880 最近在做关于Spring Boot开发的项目,因为项目中要用到Velocit ...
- centos6.5安装pip方法
pip类似RedHat里面的yum,安装Python包非常方便.本节详细介绍pip的安装.以及使用方法. 一.pip下载安装 1.1 pip下载 wget "https://pypi.pyt ...
- django中权限控制到按钮级别
权限控制到按钮级别 : 1.思路 : 由于每个按钮都能认为是一个权限,所以每个按钮都会有一个自己的路径,这些路径都在用户登录时保存在了session ...
- JQuery实践--动画
显示和隐藏没有动画的元素 使包装集里的元素隐藏 hide(speed,callback) speed:可选,速度.slow,normal,fastcallback:函数,可选,完成后调用的函数,无参数 ...