Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sameBST(arr1, arr2) {
- if (arr1.length !== arr2.length) return false;
- if (!arr1.length && !arr2.length) return true;
- const left1 = [];
- const left2 = [];
- const right1 = [];
- const right2 = [];
- const root1 = arr1[0];
- const root2 = arr2[0];
- if (root1 !== root2)
- return false;
- for (let i = 1; i < arr1.length; i++) {
- arr1[i] < root1 ? left1.push(arr1[i]) : right1.push(arr1[i]);
- arr2[i] < root2 ? left2.push(arr2[i]) : right2.push(arr2[i]);
- }
- return sameBST(left1, left2) && sameBST(right1, right2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement