JSFiddle - React, Tailwind, and code Playground
by ovo1381
JavaScript
const assert = require('assert');
class BSTNode {
constructor(value, [left, right] = []) {
this.value = value;
this.left = left;
this.right = right;
}
}
/**
* Test 를 통과하도록 Binary search tree 의 유효성을 검사하는 코드를 작성해주세요
*
* Binary search tree 란?
* ---
* A node-based binary tree data structure which has the following properties:
* 1. The left subtree of a node contains only nodes with values **less than** the node's value.
* 2. The right subtree of a node contains only nodes with values **greater than** the node's value.
* 3. Both the left and right subtrees must also be binary search trees.
*/
function isValidBSTNode(bstNode) {
return true;
}
// Test
const validBSTNode = new BSTNode(2, [new BSTNode(1), new BSTNode(3)]);
assert.equal(isValidBSTNode(validBSTNode), true);
const invalidBSTNode = new BSTNode(5, [new BSTNode(1), new BSTNode(4, [new BSTNode(3), new BSTNode(6)])]);
assert.equal(isValidBSTNode(invalidBSTNode), false);