《从上往下打印二叉树》这道题为什么这样的代码不能通过?

public static ArrayListPrintFromTopToBottom(TreeNode root) 
        ArrayList array = new ArrayList();
         if (root == null) 
             return null; 
        Queue nodes = new LinkedList(); 
        nodes.offer(root);
        while (nodes.size() > 0) { 
                TreeNode pnode = nodes.poll();
                array.add(pnode.val);
                if (pnode.left != null) 
                    nodes.offer(pnode.left); 
                if (pnode.right != null)
                    nodes.offer(pnode.right); 
             }
         if (array.isEmpty()) { 
                 return null;
         } else { 
                 return array;
         }
 }
#Java工程师##算法工程师#
全部评论
已解决代码如下: public class Solution {     public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) {          ArrayList array = new ArrayList();          if (root == null)               return array;          Queue<TreeNode> nodes = new LinkedList<TreeNode>();         nodes.offer(root);         while (nodes.size() > 0) {                  TreeNode pnode = nodes.poll();                 array.add(pnode.val);                 if (pnode.left != null)                      nodes.offer(pnode.left);                  if (pnode.right != null)                     nodes.offer(pnode.right);               }          if (array.isEmpty()) {                   return null;          } else {                   return array;          }     } }
点赞 回复 分享
发布于 2015-08-31 23:26
提交之后
点赞 回复 分享
发布于 2015-08-31 19:42
代码怎么是static方法了?
点赞 回复 分享
发布于 2015-08-31 00:22

相关推荐

05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-02 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务