Validate Binary Search Tree - Leetcode 98

preview_player
Показать описание
Validate Binary Search Tree - Leetcode 98
Рекомендации по теме
Комментарии
Автор

Master trees, BSTs, and all data structures and algos for FREE at Algomap.io :)

GregHogg
Автор

Man I’ve been studying for months and thought I was making progress until I found your shorts 😅 I’m not even close to interview ready.

griffinulsh
Автор

One other solution is, If you do inorder traversal on binary search tree and if it is valid tree. You will get the result in sorted order.

So apply inorder traversal, keep track of last found element, if new element is less than the previous it means, this is not valid BST.

LearnwithChampzz-rvlk
Автор

What happens if you have duplicate values? This should not be possible in a BST. I was stuck today with that possibility
Is the line of <= or >= that check this?
Thanks!

diego
Автор

You flashed the solution quick but it looks like you’re doing a bfs?

rdubb