Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.hackerrank.com/challenges/ctci-is-binary-search-tree
- /* Hidden stub code will pass a root argument to the function below. Complete the function to solve the challenge. Hint: you may want to write one or more helper functions.
- The Node class is defined as follows:
- class Node {
- int data;
- Node left;
- Node right;
- }
- */
- boolean checkBST(Node root) {
- if(root.left != null){
- if(root.left.data < root.data){//ez a helyes
- if(!checkBST(root.left)){
- return false;
- }
- }
- else{//nem felel meg
- return false;
- }
- }
- if(root.right != null){
- if(root.right.data > root.data){//ez a helyes
- if(!checkBST(root.right)){
- return false;
- }
- }
- else{
- return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement