avatar
伊朗和叙利亚总统# Joke - 肚皮舞运动
o*d
1
今天发生两次了,c++, 同样的test case,我用VS2010和cygwin都测试没问题,leetcode就
是fail........
比如这个:
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isValidBST(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
// Start typing your C/C++ solution below
// DO NOT write int main() function
static TreeNode* prevNode = NULL;

if (!root)
return true;

//in-order trav
if(!isValidBST(root->left))
return false;

if((prevNode)&&(prevNode->val>=root->val))
return false;

prevNode = root;

if(!isValidBST(root->right))
return false;

return true;

}
};
//--------------测试结果
input output expected
{} true true

{0} true true

{1} true true

{1,1} false false

{1,#,1} false false

{0,-1} false true

{0,#,-1} false false

{0,1} false false

{0,#,1} true true

{2,1,3} true true

{10,5,15,#,#,6,20} false false

{3,1,5,0,2,4,6} false true

{3,1,5,0,2,4,6,#,#,#,3} false false

但是我用VS2010测过{0,-1}的case,没问题啊
//---------my test code-----------
int main()
{
TreeNode node(0);
TreeNode left(-1);
node.left = &left;
Solution sol;
bool bT = sol.isValidBST(&node);
cout << bT << endl;
}
avatar
m*y
2
在联大开会时被拘留
avatar
l*a
3
你试试用visual studio跑一堆case看看结果
不要只跑一个

leetcode就

【在 o***d 的大作中提到】
: 今天发生两次了,c++, 同样的test case,我用VS2010和cygwin都测试没问题,leetcode就
: 是fail........
: 比如这个:
: /**
: * Definition for binary tree
: * struct TreeNode {
: * int val;
: * TreeNode *left;
: * TreeNode *right;
: * TreeNode(int x) : val(x), left(NULL), right(NULL) {}

avatar
r*e
4
一个小时给多少钱?

【在 m***y 的大作中提到】
: 在联大开会时被拘留
avatar
o*d
5
okay, 我try try

【在 l*****a 的大作中提到】
: 你试试用visual studio跑一堆case看看结果
: 不要只跑一个
:
: leetcode就

avatar
C*e
6
欺软怕硬
avatar
l*a
7
what is the result?

【在 o***d 的大作中提到】
: okay, 我try try
avatar
l*t
8
因为Leetcode用同一个class/函数测试很多cases,所以你这个
static TreeNode* prevNode = NULL;
可能在case和case之间会出问题。
avatar
o*d
9
确实如此,不用static就好了
thanks

【在 l********t 的大作中提到】
: 因为Leetcode用同一个class/函数测试很多cases,所以你这个
: static TreeNode* prevNode = NULL;
: 可能在case和case之间会出问题。

avatar
f*7
10
我都是直接在leetcode上直接写C++的
出bug了裸眼看
有一两题实在搞不定的
再用visual studio调试
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。