@@ -0,0 +1,2319 @@
+package com.anuragkapur.leetcode;%0A%0Aimport java.util.Deque;%0Aimport java.util.LinkedList;%0A%0A/**%0A * Definition for a binary tree node.%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; %7D%0A * %7D%0A */%0Apublic class CountCompleteTreeNodes %7B%0A%0A    public int countNodes(TreeNode root) %7B%0A%0A        if(root == null) %7B%0A            return -1;%0A        %7D%0A%0A        // compute height%0A        TreeNode current = root;%0A        int height = -1;%0A        while(current != null) %7B%0A            height ++;%0A            current = current.left;%0A        %7D%0A%0A        // count leaves%0A        int leaves = countLeaves(root, height);%0A%0A        // compute node count%0A        int count = 0;%0A        for(int i=0; i%3Cheight; i++) %7B%0A            count += Math.pow(2, i);%0A        %7D%0A        count += leaves;%0A%0A        return count;%0A    %7D%0A%0A    private int countLeaves(TreeNode root, int height) %7B%0A%0A        int leaves = 0;%0A        Deque%3CTreeNodeWithLevel%3E stack = new LinkedList%3C%3E();%0A        stack.push(new TreeNodeWithLevel(root, 0));%0A        boolean incompleteBranchFound = false;%0A%0A        while(!stack.isEmpty()) %7B%0A%0A            if (incompleteBranchFound) %7B%0A                break;%0A            %7D%0A%0A            TreeNodeWithLevel current = stack.pop();%0A%0A            if (current.level == height) %7B%0A                leaves ++;%0A            %7D else %7B%0A                if (current.treeNode.right == null) %7B%0A                    incompleteBranchFound = true;%0A                %7D%0A                if (current.treeNode.left != null) %7B%0A                    leaves ++;%0A                %7D%0A            %7D%0A%0A            if (current.treeNode.right != null) %7B%0A                stack.push(new TreeNodeWithLevel(current.treeNode.right, current.level+1));%0A            %7D%0A            if (current.treeNode.left != null) %7B%0A                stack.push(new TreeNodeWithLevel(current.treeNode.left, current.level+1));%0A            %7D%0A        %7D%0A%0A        return leaves;%0A    %7D%0A%0A    private class TreeNodeWithLevel %7B%0A        TreeNode treeNode;%0A        int level;%0A        TreeNodeWithLevel(TreeNode treeNode, int level) %7B%0A            this.treeNode = treeNode;%0A            this.level = level;%0A        %7D%0A    %7D%0A%0A    private class TreeNode %7B%0A        int val;%0A        TreeNode left;%0A        TreeNode right;%0A        TreeNode(int x) %7B val = x; %7D%0A    %7D%0A%7D

Add problem #222 wip code