mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	国外版
This commit is contained in:
		
							
								
								
									
										41
									
								
								算法题(国外版)/count-good-nodes-in-binary-tree.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								算法题(国外版)/count-good-nodes-in-binary-tree.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
<p>Given a binary tree <code>root</code>, a node <em>X</em> in the tree is named <strong>good</strong> if in the path from root to <em>X</em> there are no nodes with a value <em>greater than</em> X.</p>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<p>Return the number of <strong>good</strong> nodes in the binary tree.</p>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 1:</strong></p>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/test_sample_1.png" style="width: 263px; height: 156px;" /></strong></p>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
 | 
			
		||||
<strong>Input:</strong> root = [3,1,4,3,null,1,5]
 | 
			
		||||
 | 
			
		||||
<strong>Output:</strong> 4
 | 
			
		||||
 | 
			
		||||
<strong>Explanation:</strong> Nodes in blue are <strong>good</strong>.
 | 
			
		||||
 | 
			
		||||
Root Node (3) is always a good node.
 | 
			
		||||
 | 
			
		||||
Node 4 -> (3,4) is the maximum value in the path starting from the root.
 | 
			
		||||
 | 
			
		||||
Node 5 -> (3,4,5) is the maximum value in the path
 | 
			
		||||
 | 
			
		||||
Node 3 -> (3,1,3) is the maximum value in the path.</pre>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 2:</strong></p>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/04/02/test_sample_2.png" style="width: 157px; height: 161px;" /></strong></p>
 | 
			
		||||
		Reference in New Issue
	
	Block a user