정렬된 배열을 이진탐색트리로 변환 및 이진탐색트리 조작 기법
108. 정렬된 배열을 이진 탐색 트리로 변환
재귀적 접근
class Solution {
private:
TreeNode* buildTree(vector<int>& arr, int start, int end) {
if (start > end) return nullptr;
int center = start + (end - start) / 2;
TreeNode* node = new TreeNode(arr[center]);
node->left = buildTree(arr, start, center - 1);
...
6월 3일 16:01에 게시됨