0.code
class Solution {
public boolean verifyPostorder(int[] postorder) {
if(postorder==null||postorder.length==0){
return true;
}
int len = postorder.length;
return verifyPostorderHelp(postorder,0,len-1);
}
public boolean verifyPostorderHelp(int[] postorder,int start,int end){
if(start>=end){
return true;
}
int m = start;
for(int i=start;i<=end-1;i++){
if(postorder[i]<postorder[end]){
m=i;
}else{
break;
}
}
m++;
for(int i=m;i<end;i++){
if(postorder[i]<=postorder[end]){
return false;
}
}
return verifyPostorderHelp(postorder,start,m-1)&&verifyPostorderHelp(postorder,m,end-1);
}
}
网友评论