Minimum Numbers of Function Calls to Make Target Array LeetCode solution in Python
1# Observe that:2# +1 places a 1 to the end of the int's binary representation3# (assuming a 0 there previously)4# x2 is a bitshift left5# So you basically just need to count all the ones in the binary representations6# and find how many shifts are required (largest bit length minus one).789class Solution:10def minOperations(self, nums: List[int]) -> int:11if max(nums) == 0:12return 01314return (15sum([x.bit_count() for x in nums]) + max([x.bit_length() for x in nums]) - 116)