(root, hash, postOrderKey)
| 66 | }; |
| 67 | |
| 68 | const hashify = (root, hash, postOrderKey) => { |
| 69 | if (!root) return '#'; |
| 70 | |
| 71 | const left = hashify(root.left, hash, postOrderKey); |
| 72 | const right = hashify(root.right, hash, postOrderKey); |
| 73 | |
| 74 | const key = [left, root.val, right].join(''); |
| 75 | |
| 76 | if (!hash.has(key)) { |
| 77 | hash.set(key, postOrderKey[0]); |
| 78 | postOrderKey[0]++; |
| 79 | } |
| 80 | |
| 81 | return hash.get(key); |
| 82 | }; |
| 83 | |
| 84 | var isSubtree = function (root, subRoot, hash = new Map(), postOrderKey = [0]) { |
| 85 | hashify(root, hash, postOrderKey); |