首页
IT
登录
6mi
u
盘
搜
搜 索
IT
求二叉排序树的最小根
求二叉排序树的最小根
xiaoxiao
2021-04-18
52
public
class
Solve
{
public
static
void
main
(
String
[]
args
){
int
aa
=
minRoot
(
4
,
10
,
13
);
int
bb
=
minRoot
(
4
,
aa
,
15
);
System
.
out
.
println
(
bb
);
}
public
static
int
minRoot
(
int
K
,
int
a
,
int
b
){
if
(
a
<
b
){
int
tmp
=
a
;
a
=
b
;
b
=
tmp
;
}
if
(
a
>
Math
.
pow
(
2
,
K
)
-
1
||
b
<
0
)
return
-
1
;
if
(
a
>=
Math
.
pow
(
2
,
K
-
1
)
&&
b
<=
Math
.
pow
(
2
,
K
-
1
))
{
return
(
int
)
Math
.
pow
(
2
,
K
-
1
);
}
if
(
b
>
Math
.
pow
(
2
,
K
-
1
))
{
return
(
int
)(
Math
.
pow
(
2
,
K
-
1
)+
minRoot
(
K
-
1
,(
int
)(
a
-
Math
.
pow
(
2
,
K
-
1
))
,(
int
)(
b
-
Math
.
pow
(
2
,
K
-
1
))));
}
return
minRoot
(
K
-
1
,
a
,
b
);
}
}
转载请注明原文地址: https://ju.6miu.com/read-674794.html
技术
最新回复
(
0
)