package com.fishercoder.solutions;

import com.fishercoder.common.classes.Node;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * 429. N-ary Tree Level Order Traversal
 *
 * Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
 *
 * For example, given a 3-ary tree:
 *
 *                              1
 *                            / | \
 *                           3  2 4
 *                          / \
 *                         5  6
 *
 *  We should return its level order traversal:
 *
 * [
 *      [1],
 *      [3,2,4],
 *      [5,6]
 * ]
 *
 *
 * Note:
 *
 * The depth of the tree is at most 1000.
 * The total number of nodes is at most 5000.
 */
public class _429 {
  public static class Solution1 {
    public List<List<Integer>> levelOrder(Node root) {
      List<List<Integer>> result = new ArrayList<>();
      if (root == null) {
        return result;
      }
      Queue<Node> queue = new LinkedList<>();
      queue.offer(root);
      while (!queue.isEmpty()) {
        int size = queue.size();
        List<Integer> level = new ArrayList<>();
        for (int i = 0; i < size; i++) {
          Node currentNode = queue.poll();
          if (currentNode != null) {
            level.add(currentNode.val);
            for (Node child : currentNode.children) {
              queue.offer(child);
            }
          }
        }
        result.add(level);
      }
      return result;
    }
  }
}

@@ -73,16 +73,17 @@
 s.Node;%0A
+%0A
 import j
@@ -183,607 +183,8 @@
 e;%0A%0A
-/**%0A * 429. N-ary Tree Level Order Traversal%0A *%0A * Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).%0A *%0A * For example, given a 3-ary tree:%0A *%0A *                              1%0A *                            / %7C %5C%0A *                           3  2 4%0A *                          / %5C%0A *                         5  6%0A *%0A *  We should return its level order traversal:%0A *%0A * %5B%0A *      %5B1%5D,%0A *      %5B3,2,4%5D,%0A *      %5B5,6%5D%0A * %5D%0A *%0A *%0A * Note:%0A *%0A * The depth of the tree is at most 1000.%0A * The total number of nodes is at most 5000.%0A */%0A
 publ
@@ -199,16 +199,18 @@
  _429 %7B%0A
+  
   public
@@ -235,24 +235,28 @@
 tion1 %7B%0A    
+   
+ 
 public List%3C
@@ -296,24 +296,30 @@
 ot) %7B%0A      
+     
+ 
 List%3CList%3CIn
@@ -356,24 +356,30 @@
 %3C%3E();%0A      
+     
+ 
 if (root == 
@@ -378,32 +378,40 @@
 root == null) %7B%0A
+        
         return r
@@ -419,26 +419,38 @@
 sult;%0A      
+   
-%7D%0A
+   %7D%0A      
       Queue%3C
@@ -485,24 +485,30 @@
 %3C%3E();%0A      
+   
+   
 queue.offer(
@@ -514,16 +514,22 @@
 (root);%0A
+      
       wh
@@ -561,16 +561,24 @@
         
+    
+    
 int size
@@ -590,24 +590,32 @@
 eue.size();%0A
+        
         List
@@ -643,32 +643,40 @@
  ArrayList%3C%3E();%0A
+        
         for (int
@@ -710,16 +710,26 @@
         
+    
+      
 Node cur
@@ -759,24 +759,34 @@
 ;%0A          
+      
+    
 if (currentN
@@ -812,16 +812,28 @@
         
+         
+   
 level.ad
@@ -860,24 +860,36 @@
             
+         
+   
 for (Node ch
@@ -914,24 +914,38 @@
 children) %7B%0A
+              
             
@@ -982,40 +982,72 @@
     
+       
-%7D%0A          %7D%0A        %7D%0A
+     %7D%0A                    %7D%0A                %7D%0A  
         
 resu
@@ -1042,16 +1042,22 @@
         
+      
 result.a
@@ -1067,24 +1067,30 @@
 level);%0A
+      
       %7D%0A
       re
@@ -1077,24 +1077,30 @@
           %7D%0A
+      
       return
@@ -1112,16 +1112,22 @@
 lt;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 429