(root, subRoot)
| 5 | * @return {boolean} |
| 6 | */ |
| 7 | var isSubtree = function (root, subRoot) { |
| 8 | if (!root) return false; |
| 9 | |
| 10 | if (isSame(root, subRoot)) return true; |
| 11 | |
| 12 | const hasLeftTree = isSubtree(root.left, subRoot); |
| 13 | const hasRightTree = isSubtree(root.right, subRoot); |
| 14 | |
| 15 | return hasLeftTree || hasRightTree; |
| 16 | }; |
| 17 | |
| 18 | const isSame = (root, subRoot) => { |
| 19 | const hasReachedEnd = !(root && subRoot); |
nothing calls this directly
no test coverage detected