mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			29 lines
		
	
	
		
			595 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			595 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Implement a function to check if a binary tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.</p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p><br />
 | 
						|
 | 
						|
<strong>Example 1:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<pre>
 | 
						|
 | 
						|
Given tree [3,9,20,null,null,15,7]
 | 
						|
 | 
						|
    3
 | 
						|
 | 
						|
   / \
 | 
						|
 | 
						|
  9  20
 | 
						|
 | 
						|
    /  \
 | 
						|
 | 
						|
   15   7
 | 
						|
 | 
						|
return true.</pre>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p><strong>Example 2:</strong></p>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<pre>
 | 
						|
 | 
						|
Given [1,2,2,3,3,null,null,4,4]
 | 
						|
 | 
						|
      1
 | 
						|
 | 
						|
     / \
 | 
						|
 | 
						|
    2   2
 | 
						|
 | 
						|
   / \
 | 
						|
 | 
						|
  3   3
 | 
						|
 | 
						|
 / \
 | 
						|
 | 
						|
4   4
 | 
						|
 | 
						|
return false.</pre>
 | 
						|
 | 
						|
 | 
						|
 | 
						|
<p> </p>
 | 
						|
 |