Skip to content

3173. Bitwise OR of Adjacent Elements 👍

  • Time: $O(n)$
  • Space: $O(n)$
1
2
3
4
5
6
7
8
9
class Solution {
 public:
  vector<int> orArray(vector<int>& nums) {
    vector<int> ans;
    for (int i = 1; i < nums.size(); ++i)
      ans.push_back(nums[i - 1] | nums[i]);
    return ans;
  }
};
1
2
3
4
5
6
7
8
class Solution {
  public int[] orArray(int[] nums) {
    int[] ans = new int[nums.length - 1];
    for (int i = 0; i < nums.length - 1; ++i)
      ans[i] = nums[i] | nums[i + 1];
    return ans;
  }
}
1
2
3
class Solution:
  def orArray(self, nums: list[int]) -> list[int]:
    return [a | b for a, b in itertools.pairwise(nums)]