package leetcode;

/**
 * https://leetcode.com/problems/count-complete-tree-nodes/
 */
public class Problem222 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

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

    public int countNodes(TreeNode root) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem222 prob = new Problem222();
    }
}

@@ -279,173 +279,1843 @@
    p
-ublic int countNodes(TreeNode root) %7B%0A        // TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem222 prob = new Problem222(
+rivate static class Count %7B%0A        int count;%0A        boolean done;%0A    %7D%0A%0A    public int countNodes(TreeNode root) %7B%0A        int maxLevel = getNumLevel(root, 0);%0A//        System.out.println(%22maxlevel=%22 + maxLevel);%0A        Count incomplete = new Count();%0A        countIncomplete(root, maxLevel, 0, incomplete);%0A//        System.out.println(%22countIncomplete=%22 + countIncomplete);%0A        return (int) (Math.pow(2, maxLevel) - 1) - incomplete.count;%0A    %7D%0A%0A    private void countIncomplete(TreeNode node, int maxLevel, int level, Count count) %7B%0A        if (node == null) %7B%0A            if (maxLevel %3E level) %7B%0A                count.count++;%0A                return;%0A            %7D%0A            count.done = true;%0A            return;%0A        %7D%0A        countIncomplete(node.right, maxLevel, level + 1, count);%0A        if (count.done) %7B%0A            return;%0A        %7D%0A        countIncomplete(node.left, maxLevel, level + 1, count);%0A        if (count.done) %7B%0A            return;%0A        %7D%0A    %7D%0A%0A    private int getNumLevel(TreeNode node, int level) %7B%0A        if (node == null) %7B%0A            return level;%0A        %7D%0A        return getNumLevel(node.left, level + 1);%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem222 prob = new Problem222();%0A%0A        TreeNode root = new TreeNode(1);%0A        root.left = new TreeNode(2);%0A        root.left.left = new TreeNode(3);%0A        root.left.left.left = new TreeNode(4);%0A        root.left.left.right = new TreeNode(5);%0A        root.left.right = new TreeNode(6);%0A        root.left.right.left = new TreeNode(7);%0A        root.left.right.right = new TreeNode(8);%0A        root.right = new TreeNode(9);%0A        root.right.left = new TreeNode(10);%0A        root.right.left.left = new TreeNode(11);%0A        root.right.right = new TreeNode(12);%0A%0A        System.out.println(prob.countNodes(root)
 );%0A 

Update problem 222