# 1448. Count Good Nodes in Binary Tree

[Link](https://leetcode.com/problems/count-good-nodes-in-binary-tree/)

**Solution**

Recursive calculate the node with DFS

```java
   int count = 0;
    public int goodNodes(TreeNode root) {
        dfs(root, -10000);
        return count;
    }
    
    public void dfs(TreeNode node, int max){
        
        if(node == null) return;
        
        if(node.val >= max){
            max = node.val;
            count++;
        }
        dfs(node.left, max);
        dfs(node.right, max);
    }
```
