(root, subRoot)
| 16 | }; |
| 17 | |
| 18 | const isSame = (root, subRoot) => { |
| 19 | const hasReachedEnd = !(root && subRoot); |
| 20 | if (hasReachedEnd) return root === subRoot; |
| 21 | |
| 22 | const isMismatch = root.val !== subRoot.val; |
| 23 | if (isMismatch) return false; |
| 24 | |
| 25 | const isLeftSame = isSame(root.left, subRoot.left); |
| 26 | const isRightSame = isSame(root.right, subRoot.right); |
| 27 | |
| 28 | return isLeftSame && isRightSame; |
| 29 | }; |
| 30 | |
| 31 | const hash = (val) => |
| 32 | require('crypto').createHash('md5').update(val).digest('hex'); |