@@ -0,0 +1,1869 @@
+package binarytree;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport datastructures.tree.BinaryTree;%0Aimport datastructures.tree.TreeNode;%0A%0Apublic class CountHalfNodesBinaryTree %7B%0A  private BinaryTree%3CInteger%3E tree = null;%0A  private Map%3CInteger, TreeNode%3CInteger%3E%3E nodesMap = null;%0A  private TreeNode%3CInteger%3E root = null;%0A%0A  public CountHalfNodesBinaryTree() %7B%0A    tree = new BinaryTree%3CInteger%3E();%0A    nodesMap = new HashMap%3CInteger, TreeNode%3CInteger%3E%3E();%0A  %7D%0A%0A  public void constructTree(String%5B%5D input) %7B%0A    for (String line : input) %7B%0A      String%5B%5D values = line.split(%22 %22);%0A      int val = 0;%0A      switch (values%5B0%5D) %7B%0A      case %22insertRoot%22:%0A        val = Integer.parseInt(values%5B1%5D);%0A        TreeNode%3CInteger%3E root = tree.insertRoot(val);%0A        if (root != null) %7B%0A          nodesMap.put(val, root);%0A          this.root = root;%0A        %7D%0A        break;%0A      case %22insertLeft%22:%0A        insert(values%5B1%5D, values%5B2%5D, true);%0A        break;%0A      case %22insertRight%22:%0A        insert(values%5B1%5D, values%5B2%5D, false);%0A        break;%0A      %7D%0A    %7D%0A  %7D%0A%0A  private void insert(String parentStr, String nodeStr, boolean isLeft) %7B%0A    int parentVal = Integer.parseInt(parentStr);%0A    int nodeVal = Integer.parseInt(nodeStr);%0A    TreeNode%3CInteger%3E parentNode = nodesMap.get(parentVal);%0A    if (parentNode == null) %7B%0A      return;%0A    %7D%0A%0A    TreeNode%3CInteger%3E node = new TreeNode%3CInteger%3E(nodeVal);%0A    nodesMap.put(nodeVal, tree.insert(parentNode, node, isLeft));%0A  %7D%0A%0A  public int countHalfNodes() %7B%0A    return countHalfNodes(root);%0A  %7D%0A%0A  private int countHalfNodes(TreeNode%3CInteger%3E root) %7B%0A    if (root == null %7C%7C (root.left == null && root.right == null)) %7B%0A      return 0;%0A    %7D else %7B%0A      int numHalfNodes = (root.left == null %7C%7C root.right == null) ? 1 : 0;%0A      return countHalfNodes(root.left) + countHalfNodes(root.right) + numHalfNodes;%0A    %7D%0A  %7D%0A%7D%0A

Add solution for count half nodes in a binary tree