function minimumStep(n = 1) { // 转化为二进制,那么从0b1到0b1xxx,左移1位是x2,+1是+1 const binary = n.toString(2); let zeroCount = 0; let oneCount = 0; for (let str of binary.slice(1)) { if (str === "0") { // 多一个0需要1步:+1 zeroCount++; } else { // 多一个1需要2步:+1 x2 oneCount++; } } return zeroCount + oneCount * 2; }