Count Complete Tree Nodes LeetCode solution in Java

1
/**
2
* Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode
3
* 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
*/
6
class Solution {
7

8
static int count = 0;
9

10
static void Postorder(TreeNode root) {
11
if (root == null) {
12
return;
13
}
14
Postorder(root.left);
15
Postorder(root.right);
16
count++;
17
}
18

19
public int countNodes(TreeNode root) {
20
count = 0;
21
Postorder(root);
22
return count;
23
}
24
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0