banner
cells

cells

为美好的世界献上 bug

2917. Find the K-or value in the array

2917. Find the K-th OR Value in an Array#

Given an integer array nums and an integer k, return the k-th OR value of nums.

The k-th OR value of nums is a non-negative integer that satisfies the following conditions:

  • Only if there are at least k elements in nums whose i-th bit is 1, then the i-th bit of the OR value is 1.

Return the k-th OR value of nums.

Note: For an integer x, if (2^i AND x) == 2^i, then the i-th bit of x is 1, where AND is the bitwise AND operator.

Example 1:

Example 2:

Example 3:

Constraints:

  • 1 <= nums.length <= 50
  • 0 <= nums[i] < 2^31
  • 1 <= k <= nums.length

Bit Manipulation#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.