-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy path33.java
More file actions
51 lines (30 loc) · 708 Bytes
/
33.java
File metadata and controls
51 lines (30 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Solution {
public boolean verifyPostorder(int[] postorder) {
if(postorder.length==0)
{
return true;
}
return find(postorder,0,postorder.length-1);
}
public boolean find(int[] postorder,int start,int end)
{
if(start>=end)
{
return true;
}
int i = start,j = end-1;
while(i<end&&postorder[i]<postorder[end])
{
i++;
}
while(j>start&&postorder[j]>postorder[end])
{
j--;
}
if(i<j)
{
return false;
}
return find(postorder,start,i-1)&&find(postorder,j+1,end-1);
}
}