C
C#15mo ago
morry329#

❔ Comprehension questions for the LC solution

So I take a look at this solution right now: https://leetcode.com/problems/validate-binary-search-tree/solutions/3327674/simple-c-code/?envType=study-plan&id=level-1&languageTags=csharp There are a couple of lines I did not understand fully. 1. the check l[i]>=l[i+1] in the bool method. What could it mean? 2. In the helper method (Inorder) the root.val is added after the list looks at the left node of the root node and before it looks at the right node of the root node. Why is it like that? Could anyone kindly explain those to me?
LeetCode
Simple C# code - Validate Binary Search Tree - LeetCode
View VikasSinghThakur07's solution of Validate Binary Search Tree on LeetCode, the world's largest programming community.
3 Replies
Florian Voß
Florian Voß15mo ago
1. the check translates to if left node ist greater or equal to right node. If thats true then it ain't a valid BST so false gets returned. 2. root.val gets added after left.val and before right.val because well thats how a BST is defined. If we look at this section right here on my picture, we can see that 3 is smaller than 8 and 8 is smaller than 10. So if we wanna order these values we add 3, then 8, then 10 to the list
morry329#
morry329#15mo ago
Thanks a lot 🙂
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.