Tap here to switch tabs
Problem
Submissions

Problem: Count Good Nodes in Binary Tree

Try to solve the Count Good Nodes in Binary Tree problem.

Statement

Given the root of a binary tree, a node X is considered good if on the path from the root to X, there are no nodes with a value greater than X.

Return the total number of good nodes in the binary tree.

Constraints:

  • The number of nodes in the binary tree is in the range [1,105][1, 10^5].

  • −104≤-10^4 \leq Node.val ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Good Nodes in Binary Tree

Try to solve the Count Good Nodes in Binary Tree problem.

Statement

Given the root of a binary tree, a node X is considered good if on the path from the root to X, there are no nodes with a value greater than X.

Return the total number of good nodes in the binary tree.

Constraints:

  • The number of nodes in the binary tree is in the range [1,105][1, 10^5].

  • −104≤-10^4 \leq Node.val ≤104\leq 10^4