Class Solution
-
- All Implemented Interfaces:
public final class Solution
3315 - Construct the Minimum Bitwise Array II.
Medium
You are given an array
nums
consisting ofn
prime integers.You need to construct an array
ans
of lengthn
, such that, for each indexi
, the bitwiseOR
ofans[i]
andans[i] + 1
is equal tonums[i]
, i.e.ans[i] OR (ans[i] + 1) == nums[i]
.Additionally, you must minimize each value of
ans[i]
in the resulting array.If it is not possible to find such a value for
ans[i]
that satisfies the condition , then setans[i] = -1
.Example 1:
Input: nums = 2,3,5,7
Output: -1,1,4,3
Explanation:
For
i = 0
, as there is no value forans[0]
that satisfiesans[0] OR (ans[0] + 1) = 2
, soans[0] = -1
.For
i = 1
, the smallestans[1]
that satisfiesans[1] OR (ans[1] + 1) = 3
is1
, because1 OR (1 + 1) = 3
.For
i = 2
, the smallestans[2]
that satisfiesans[2] OR (ans[2] + 1) = 5
is4
, because4 OR (4 + 1) = 5
.For
i = 3
, the smallestans[3]
that satisfiesans[3] OR (ans[3] + 1) = 7
is3
, because3 OR (3 + 1) = 7
.
Example 2:
Input: nums = 11,13,31
Output: 9,12,15
Explanation:
For
i = 0
, the smallestans[0]
that satisfiesans[0] OR (ans[0] + 1) = 11
is9
, because9 OR (9 + 1) = 11
.For
i = 1
, the smallestans[1]
that satisfiesans[1] OR (ans[1] + 1) = 13
is12
, because12 OR (12 + 1) = 13
.For
i = 2
, the smallestans[2]
that satisfiesans[2] OR (ans[2] + 1) = 31
is15
, because15 OR (15 + 1) = 31
.
Constraints:
1 <= nums.length <= 100
<code>2 <= numsi<= 10<sup>9</sup></code>
nums[i]
is a prime number.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntArray
minBitwiseArray(List<Integer> nums)
-
-
Method Detail
-
minBitwiseArray
final IntArray minBitwiseArray(List<Integer> nums)
-
-
-
-