MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / isSymmetric

Method isSymmetric

src/com/blankj/easy/_0101/Solution.java:27–45  ·  view source on GitHub ↗
(TreeNode root)

Source from the content-addressed store, hash-verified

25// }
26
27 public boolean isSymmetric(TreeNode root) {
28 if (root == null) return true;
29 LinkedList<TreeNode> q = new LinkedList<>();
30 q.add(root.left);
31 q.add(root.right);
32 TreeNode left, right;
33 while (q.size() > 1) {
34 left = q.pop();
35 right = q.pop();
36 if (left == null && right == null) continue;
37 if (left == null || right == null) return false;
38 if (left.val != right.val) return false;
39 q.add(left.left);
40 q.add(right.right);
41 q.add(left.right);
42 q.add(right.left);
43 }
44 return true;
45 }
46
47 public static void main(String[] args) {
48 Solution solution = new Solution();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected