1
var isUnivalTree = function (root) {
2
if (!root) {
3
return false;
4
}
5

6
const prev = root.val;
7
const nodes = [root];
8

9
for (const node of nodes) {
10
if (node.val !== prev) {
11
return false;
12
}
13

14
if (node.left) {
15
nodes.push(node.left);
16
}
17

18
if (node.right) {
19
nodes.push(node.right);
20
}
21
}
22

23
return true;
24
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0