当 i 在每次迭代中加倍时,时间复杂度是多少?

What would be the time complexity of this when i is doubled in each iteration?

int i = 1;
while(i < N) {
  i *= 2;
}

因为我们正在访问 1,2,4,8,16...(正方形)。我认为 big-O 时间复杂度应该是 O(log n)。答案正确吗?我得出解决方案的方式是否正确?

是的,你的回答是正确的。一般来说,如果一个值呈指数增长,那么在超过某个固定值之前,它只能以对数形式增长很多次。