share my easy understand solution--Java_2ms

  • 0

    public class Solution {
    public List<List<Integer>> zigzagLevelOrder(TreeNode root) {

        List<List<Integer>> res= new ArrayList<List<Integer>>();
          if(root==null) return res;
         for(int i=0; i< res.size();i++){
             if (i%2!=0)  Collections.reverse(res.get(i));
         return res;
    public void help(TreeNode root, int height, List<List<Integer>> res){
        if(res.size()<=height) res.add(new ArrayList<Integer>());
        if(root.left!=null) help(root.left, height+1, res);
           if(root.right!=null) help(root.right, height+1, res);


Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.