How to check if an integer is a power of 3?

前端 未结 23 1100
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 08:15

I saw this question, and pop up this idea.

23条回答
  •  一整个雨季
    2020-12-02 08:27

    How large is your input? With O(log(N)) memory you can do faster, O(log(log(N)). Precompute the powers of 3 and then do a binary search on the precomputed values.

提交回复
热议问题