MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Sanghoo

Class Sanghoo

LeetCode/BFS/965. Univalued Binary Tree/Sanghoo.java:11–32  ·  view source on GitHub ↗

https://leetcode.com/problems/univalued-binary-tree/

Source from the content-addressed store, hash-verified

9 * https://leetcode.com/problems/univalued-binary-tree/
10 */
11public class Sanghoo {
12
13 public boolean isUnivalTree(TreeNode root) {
14 Queue<TreeNode> q = new ArrayDeque<>();
15 int value = 0;
16
17 q.add(root);
18 value = root.val;
19
20 while(!q.isEmpty()) {
21 TreeNode node = q.poll();
22
23 if(value != root.val) return false;
24
25 if(node.left != null) q.add(node.left);
26 if(node.right != null) q.add(node.right);
27 }
28
29 return true;
30 }
31
32}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected