leetcode:16.翻转二叉树 简单

class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(root==null){
            return null;
        }
        Queue<TreeNode> queue=new LinkedList<TreeNode>();
        queue.add(root);
        while(!queue.isEmpty()){
            TreeNode current=queue.poll();
            TreeNode tmp=current.left;
            current.left=current.right;
            current.right=tmp;
            if(current.left!=null)  
                queue.add(current.left);  
            if(current.right!=null)  
                queue.add(current.right);  
            }
         return root;
    }
}

你可能感兴趣的:(leetcode,leetcode,java,链表)