请问哪儿发生段错误呢?

class Solution {
public:
	bool VerifySquenceOfBST(vector<int> sequence) {
		if (sequence.size() <= 0)
			return false;
		int  size = sequence.size();


		return IsSe(sequence, 0, size - 1);


	}
	bool IsSe(vector<int>s, int start, int end)
	{
		if ( (end - start) <= 0)
			return true;
		int rootVal = s[end];
		int i = start;

		for (; i <= end - 1; ++i)
		{
			if (rootVal>s[i])
				break;
		}
		int j = i;
		for (; j <= end - 1; ++j)
		{
			if (s[j]<rootVal)
				return false;
		}
		bool left = false;
		bool right = false;

		if(i>0)
		   left = IsSe(s, start, i);
		if(i<end)
		   right = IsSe(s, i + 1, end - 1);

		return (left&&right);
	}

};

全部评论
第一个for 循环break那地方弄反了。。。。应该是s[i] > rootVal  
点赞 回复 分享
发布于 2016-09-01 13:37

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务