package com.freetymekiyan.algorithms.utils;

/**
 * Utility class.
 */
public class Utils {

    public static ListNode buildLinkedList(int[] values) {
        ListNode head = new ListNode(values[0]);
        ListNode cur = head;
        for (int i = 1; i < values.length; i++) {
            cur.next = new ListNode(values[i]);
            cur = cur.next;
        }
        return head;
    }

    public static class ListNode {

        public int val;
        public ListNode next;

        public ListNode(int x) {
            val = x;
        }
    }

    public static class TreeNode {

        public int val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(int x) {
            val = x;
        }
    }
}

@@ -38,16 +38,118 @@
 utils;%0A%0A
+import java.security.InvalidParameterException;%0Aimport java.util.ArrayDeque;%0Aimport java.util.Queue;%0A%0A
 /**%0A * U
@@ -481,32 +481,891 @@
 rn head;%0A    %7D%0A%0A
+    public static TreeNode buildBinaryTree(Integer%5B%5D values) %7B%0A        if (values == null %7C%7C values.length == 0) %7B%0A            throw new InvalidParameterException(%22values should not be null or empty%22);%0A        %7D%0A        TreeNode root = new TreeNode(values%5B0%5D);%0A        Queue%3CTreeNode%3E queue = new ArrayDeque%3C%3E();%0A        queue.offer(root);%0A        int i = 1;%0A        while (!queue.isEmpty() && i %3C values.length) %7B%0A            TreeNode node = queue.poll();%0A            if (i %3C values.length && values%5Bi%5D != null) %7B%0A                node.left = new TreeNode(values%5Bi%5D);%0A                queue.offer(node.left);%0A            %7D%0A            if (i + 1 %3C values.length && values%5Bi + 1%5D != null) %7B%0A                node.right = new TreeNode(values%5Bi + 1%5D);%0A                queue.offer(node.right);%0A            %7D%0A            i += 2;%0A        %7D%0A        return root;%0A    %7D%0A%0A
     public stati

update Utils