classSolution:defverifyPostorder(self,postorder: List[int]) ->bool:defdfs(nodes): n =len(nodes)if n ==0:returnTrue,None,Noneif n ==1:returnTrue, nodes[0], nodes[0] root = nodes[-1] first =0for first inrange(n):if nodes[first]> root:break left = nodes[:first] right = nodes[first: n -1] lres, lmax, lmin =dfs(left)ifnot lres or (lmax isnotNoneand lmax > root):returnFalse,None,None rres, rmax, rmin =dfs(right)ifnot rres or (rmin isnotNoneand rmin < root):returnFalse,None,NonereturnTrue, rmax if rmax isnotNoneelse root, lmin if lmin isnotNoneelse rootreturndfs(postorder)[0]