首页 > 其他 > 详细

leetcode-剑指33-OK

时间:2021-01-31 21:08:54      阅读:41      评论:0      收藏:0      [点我收藏+]
// language c
// 剑指33
// https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/


bool verifyPostorder(int* postorder, int postorderSize){
    if(postorderSize==0)
    return true;
	bool inside(int * NeedToBeJudged, int start, int end){
		if(start==end)
			return true;
		int mid = NeedToBeJudged[end];
		int p = start;
		while(NeedToBeJudged[p]<mid)	// 循环完后p指向第一个大于等于mid的值
			p++;
		bool left =true;
		for(int i =p;i<end;i++){
			if(NeedToBeJudged[i]<=mid){
				return false;
			}
		}
		bool right = true;
		if(p>start)
			left = inside(NeedToBeJudged,start,p-1);
		if(p<end)
			right = inside(NeedToBeJudged,p,end-1);
		return left&&right;
	}

	return inside(postorder,0,postorderSize-1);
}

leetcode-剑指33-OK

原文:https://www.cnblogs.com/gallien/p/14353579.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!