Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

double ans= 1; for(long i = Math.abs((long)n); i > 0; i = i >> 1, x *=x) if((i & 1) == 1) ans *= x; return n > 0 ? ans : 1/ans;

this is not a O(1) solution...

Its of O(32) or O(64) which is constant/fixed time and does not depend upon the input size, thus it can be considered as O(1)

yes, you are right, it's a concise for loop.

I'm in support that it's not O(1), O(log n) instead. Your runtime still grow when n grows. Or u sing your way of proof, all algorithm with only Integer input is O(1), since they bounded in O(2^32).

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.