LC.P1017[负二进制转换] 方法一:模拟12345678910111213141516class Solution { public String baseNeg2(int n) { if (n == 0) return "0"; StringBuilder builder = new StringBuilder(); while (n != 0) { int remainder = n % (-2); n /= -2; if (remainder < 0) { remainder += 2; ++n; } builder.append(remainder); } return builder.reverse().toString(); }} 时间复杂度:$O(logn)$ 空间复杂度:$O(1)$