2
* Definition for a binary tree node.3
* function TreeNode(val, left, right) {4
* this.val = (val===undefined ? 0 : val)5
* this.left = (left===undefined ? null : left)6
* this.right = (right===undefined ? null : right)10
* @param {TreeNode} root13
var findMode = function (root) {14
const dup = new Map();19
let max = Number.MIN_VALUE;20
for (const [key, value] of dup) {21
if (value > 1 && value >= max) {23
max = Math.max(max, value);27
return res.length > 0 ? res : [...dup.keys()];30
function helper(root, dup) {32
dup.set(root.val, ~~dup.get(root.val) + 1);33
helper(root.left, dup);34
helper(root.right, dup);