@@ -0,0 +1,1275 @@
+/**%0A * Given a complete binary tree, count the number of nodes.%0A *%0A * Definition of a complete binary tree from Wikipedia:%0A *%0A * In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last%0A * level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.%0A *%0A * Tags: Tree, Binary Search%0A *%0A * Similar Problems: (E) Closest Binary Search Tree Value%0A */%0Apublic class CountCompleteTreeNodes %7B%0A%0A    public int countNodes(TreeNode root) %7B%0A        if (root == null) %7B%0A            return 0;%0A        %7D%0A        int leftHeight = fullTreeHeight(root.left);%0A        int rightHeight = fullTreeHeight(root.right);%0A%0A        if (leftHeight == rightHeight) %7B%0A            return (1 %3C%3C leftHeight) + countNodes(root.right);%0A        %7D else %7B%0A            return (1 %3C%3C rightHeight) + countNodes(root.left);%0A        %7D%0A    %7D%0A%0A    private int fullTreeHeight(TreeNode root) %7B%0A        if (root == null) return 0;%0A        int res = 0;%0A        while (root != null) %7B%0A            root = root.left;%0A            res++;%0A        %7D%0A        return res;%0A    %7D%0A%0A    public class TreeNode %7B%0A%0A        int val;%0A        TreeNode left;%0A        TreeNode right;%0A%0A        TreeNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A%7D%0A

add 222 Count Complete Tree Nodes