We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1ad5623 commit dca54f1Copy full SHA for dca54f1
965-univalued-binary-tree.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val) {
4
+ * this.val = val;
5
+ * this.left = this.right = null;
6
+ * }
7
+ */
8
9
+ * @param {TreeNode} root
10
+ * @return {boolean}
11
12
+const isUnivalTree = function(root) {
13
+ const arr = []
14
+ dfs(root, arr)
15
+ for(let i = 1; i < arr.length; i++) {
16
+ if(arr[i] !== arr[i- 1]) return false
17
+ }
18
+ return true
19
+};
20
+
21
+function dfs(node, arr) {
22
+ if(node === null) return
23
+ arr.push(node.val)
24
+ dfs(node.left, arr)
25
+ dfs(node.right, arr)
26
+}
0 commit comments