MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / hashify

Function hashify

javascript/0572-subtree-of-another-tree.js:68–82  ·  view source on GitHub ↗
(root, hash, postOrderKey)

Source from the content-addressed store, hash-verified

66};
67
68const 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
84var isSubtree = function (root, subRoot, hash = new Map(), postOrderKey = [0]) {
85 hashify(root, hash, postOrderKey);

Callers 1

isSubtreeFunction · 0.85

Calls 2

setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected