Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/algorithmzuo/algorithm-journey
/ log2
Method
log2
src/class117/Code01_FlagPlan.java:78–84 ·
view source on GitHub ↗
(int n)
Source
from the content-addressed store, hash-verified
76
77
// <=n最接近的2的幂,是2的几次方
78
public
static
int
log2(
int
n) {
79
int
ans = 0;
80
while
((1 << ans) <= (n >> 1)) {
81
ans++;
82
}
83
return
ans;
84
}
85
86
public
static
void
build() {
87
for
(
int
i = 1; i <= n; i++) {
Callers
1
compute
Method · 0.95
Calls
no outgoing calls
Tested by
no test coverage detected