Files
cpp-flashcards/org/study_deck_02/dsa/trees/0110-balanced-binary-tree.org
T

77 lines
1.5 KiB
Org Mode
Raw Normal View History

2026-06-01 18:12:40 +08:00
#+ANKI_DECK: study_deck_02
* TODO 0110. Balanced Binary Tree :easy:
:PROPERTIES:
:NEETCODE: [[file:../../roadmap.org::*0110. Balanced Binary Tree][0110. Balanced Binary Tree]]
:END:
Given a binary tree, determine if it is *height-balanced*.
*Example 1:*
#+begin_src
Input: root = [3,9,20,null,null,15,7]
Output: true
#+end_src
*Example 2:*
#+begin_src
Input: root = [1,2,2,3,3,null,null,4,4]
Output: false
#+end_src
*Example 3:*
#+begin_src
Input: root = []
Output: true
#+end_src
*Constraints:*
- The number of nodes in the tree is in the range ~[0, 5000]~.
- ~-10^{4} <= Node.val <= 10^{4}~
** TODO Approach
Write your approach here.
** TODO Python
2026-06-05 22:32:49 +08:00
#+begin_src python :lc-problem 110 :lc-lang python3
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isBalanced(self, root: Optional[TreeNode]) -> bool:
#+end_src
** TODO C++
2026-06-05 22:32:49 +08:00
#+begin_src cpp :lc-problem 110
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
bool isBalanced(TreeNode* root) {
}
};
#+end_src