(node, arr)
| 16 | */ |
| 17 | var leafSimilar = function (root1, root2) { |
| 18 | const dfs = (node, arr) => { |
| 19 | if (!node.left && !node.right) { |
| 20 | arr.push(node.val); |
| 21 | return arr; |
| 22 | } |
| 23 | if (node.left) dfs(node.left, arr); |
| 24 | if (node.right) dfs(node.right, arr); |
| 25 | |
| 26 | return arr; |
| 27 | }; |
| 28 | |
| 29 | const arr1 = dfs(root1, []); |
| 30 | const arr2 = dfs(root2, []); |