50029. Tree Construction

難度:3.5/5

Second Try: 2/5 Used Time: 10:25

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdlib.h>
#include "tree.h"

Node* solve(int arr[], int n, int now){
if(now >= n) return NULL;

Node* root = malloc(sizeof(Node));
root->label = arr[now];
root->left = solve(arr, n, now * 2 + 1);
root->right = solve(arr, n, now * 2 + 2);
return root;
}

Node* construct(int array[], int n){
return solve(array, n, 0);
}


50029. Tree Construction
https://aaronlin1229.github.io/judgegirl_50029/
Author
Akizumi
Posted on
July 17, 2023
Licensed under