- 归纳总结
function minOperations(nums: number[]): number {
let divTwoTimes: number = 0,
plusOneTimes: number = 0;
for (let num of nums) {
let currentDiv2Times: number = 0;
while (num) {
if (num & 1) {
++plusOneTimes;
--num;
} else {
++currentDiv2Times;
num >>>= 1;
}
}
divTwoTimes = Math.max(divTwoTimes, currentDiv2Times);
}
return plusOneTimes + divTwoTimes;
};