链接:
https://www.nowcoder.com/questionTerminal/a861533d45854474ac791d90e447bafd
来源:牛客网
break
是跳出
最内层循环
,
在else中,也同样是跳出
最内层循环
来源:牛客网
java.util.Arrays;
public
class
Solution {
public
static
boolean
VerifySquenceOfBST(
int
[] sequence) {
if
(sequence==
null
||sequence.length==
0
)
return
false
;
int
root=sequence[sequence.length-
1
];
int
i=
0
;
for
(;i<sequence.length-
1
;i++){
if
(sequence[i]>root){
break
;
}
}
int
j=i;
for
(;j<sequence.length-
1
;j++){
if
(sequence[j]<root)
return
false
;
}
boolean
left=
true
;
boolean
right=
true
;
if
(i>
0
){
left=VerifySquenceOfBST(Arrays.copyOfRange(sequence,
0
, i));
}
if
(i<sequence.length-
1
)
right=VerifySquenceOfBST(Arrays.copyOfRange(sequence, i, sequence.length-
1
));
return
(left&&right);
}
}
copyOfRange
public static long[] copyOfRange(long[] original,int from, int to)
original
- the array from which a range is to be copied
from
- the initial index of the range to be copied,
inclusive 包括
to
- the final index of the range to be copied,
exclusive不包括
. (This index may lie outside the array.)
数学里的inclusive和exclusive有什么特殊概念嘛.
是不是集合里面的东西,比如说
x属于(1,3) 就是 1<x<3 代表exclusive
x属于[1,3] 是 1<=x<=3 代表inclusive
循环有for while do-while