加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

LC 898. Bitwise ORs of Subarrays

发布时间:2020-12-14 04:25:53 所属栏目:大数据 来源:网络整理
导读:? ? 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 nu

?

?

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.)

Runtime:?652 ms
Memory Usage:?49.7 MB
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();
  }
};

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读