tag:blogger.com,1999:blog-8522573717713847738.post2040648143504590774..comments2024-03-28T00:14:29.070-07:00Comments on Yu's Coding Garden : leetcode Question 122: Validate Binary Search TreeAnonymoushttp://www.blogger.com/profile/00263085222060621782noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-8522573717713847738.post-59311925418893448312016-06-29T08:38:15.825-07:002016-06-29T08:38:15.825-07:00Instead of taking INT_MAX and INT_MIN, you can tak...Instead of taking INT_MAX and INT_MIN, you can take LONG_MAX and LONG_MIN. <br />Anonymoushttps://www.blogger.com/profile/17161709555859926005noreply@blogger.comtag:blogger.com,1999:blog-8522573717713847738.post-64224364057395514032015-12-14T07:44:51.929-08:002015-12-14T07:44:51.929-08:00Hi, I've written the exact code but it gives W...Hi, I've written the exact code but it gives WA coz of the same reason. How did you overcome this ? Please updateAnonymoushttps://www.blogger.com/profile/14532149500974521812noreply@blogger.comtag:blogger.com,1999:blog-8522573717713847738.post-29095087020631362752015-01-10T23:19:34.941-08:002015-01-10T23:19:34.941-08:00Hi, your new C++ code may cause wrong answer error...Hi, your new C++ code may cause wrong answer error. Because, the tree may contain only one root node whose value might be INT_MAX or INT_MIN, which is a valid BST while in your code, it'll return false.<br /><br />Thanks,Anonymoushttps://www.blogger.com/profile/02911470140767246094noreply@blogger.comtag:blogger.com,1999:blog-8522573717713847738.post-12397208727707543412014-01-02T13:43:21.236-08:002014-01-02T13:43:21.236-08:00Hi there, thanks for pointing out the mistake. I h...Hi there, thanks for pointing out the mistake. I have made the modification, I think usually just set the pre = INT_MIN would prevent most cases for the input. Please check the new code in the post. Thanks a lot!Anonymoushttps://www.blogger.com/profile/00263085222060621782noreply@blogger.comtag:blogger.com,1999:blog-8522573717713847738.post-76163499075521617022014-01-02T07:21:45.616-08:002014-01-02T07:21:45.616-08:00key might be -1, so the comparison pre==-1 is not ...key might be -1, so the comparison pre==-1 is not always valid.<br /><br />I like your code in post "leetcode Question 75: Recover Binary Search Tree".<br />In that post, you use a pointer to store last traversed node, and it naturally enables checking NULL to know whether there is a previous one. It's a great idea.<br /><br />Or use another flag to show whether there is a previous node, like "bool started"CodeRecipehttps://www.blogger.com/profile/06916242913634632075noreply@blogger.com