## 102.二叉树的层序遍历

``````class Solution {
public List<List<Integer>> levelOrder(TreeNode root) {
List<List<Integer>> res = new ArrayList<>();
Deque<TreeNode> deq = new LinkedList<>();
if(root == null) return res;
deq.offer(root);
while(!deq.isEmpty()){
List<Integer> res1 = new ArrayList<>();
int len = deq.size();
while(len > 0){
TreeNode node = deq.poll();
if(node.left != null) deq.offer(node.left);
if(node.right != null) deq.offer(node.right);

len--;
}
}
return res;
}
}``````

## 226.翻转二叉树

``````class Solution {
public TreeNode invertTree(TreeNode root) {
if(root == null) return null;
invertTree(root.left);
invertTree(root.right);
swap(root);
return root;
}

void swap(TreeNode root){
TreeNode tmp = root.right;
root.right = root.left;
root.left = tmp;
}
}``````

## 101. 对称二叉树

``````class Solution {
public boolean isSymmetric(TreeNode root) {
return compare(root.left, root.right);
}
boolean compare(TreeNode left, TreeNode right){
if(left != null && right == null){
return false;
}
if(left == null && right != null){
return false;
}
if(left == null && right == null){
return true;
}
if(left.val != right.val){
return false;
}
boolean compareoutside = compare(left.left, right.right);
boolean compareinside = compare(left.right, right.left);
return compareinside && compareoutside;
}
}``````