Count Complete Tree Nodes LeetCode solution in Java
1/**2* Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode3* right; TreeNode() {} TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left,4* TreeNode right) { this.val = val; this.left = left; this.right = right; } }5*/6class Solution {78static int count = 0;910static void Postorder(TreeNode root) {11if (root == null) {12return;13}14Postorder(root.left);15Postorder(root.right);16count++;17}1819public int countNodes(TreeNode root) {20count = 0;21Postorder(root);22return count;23}24}