1var isUnivalTree = function (root) {2if (!root) {3return false;4}56const prev = root.val;7const nodes = [root];89for (const node of nodes) {10if (node.val !== prev) {11return false;12}1314if (node.left) {15nodes.push(node.left);16}1718if (node.right) {19nodes.push(node.right);20}21}2223return true;24};