Check for BST | Problem of the Day | GeeksForGeeks

Sdílet
Vložit
  • čas přidán 6. 09. 2024

Komentáře • 3

  • @mathematics3398
    @mathematics3398  Před měsícem

    Table of Contents
    0:00 Problem Statement
    0:52 Solution - Python
    2:29 Solution - C++

  • @mathematics3398
    @mathematics3398  Před měsícem

    class Solution:
    def is_bst_util(self, root):
    if not root:
    return True
    if not self.is_bst_util(root.left):
    return False
    if self.prev and root.data

  • @mathematics3398
    @mathematics3398  Před měsícem

    class Solution {
    public:
    Node *prev;
    bool is_bst_util(Node *root) {
    if (!root)
    return true;
    if (!is_bst_util(root->left))
    return false;
    if (prev and root->data data)
    return false;
    prev = root;
    return is_bst_util(root->right);
    }
    bool isBST(Node* root) {
    prev = NULL;
    return is_bst_util(root);
    }
    };