LCP 67
This commit is contained in:
37
src/lcp_67.c
Normal file
37
src/lcp_67.c
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by xfj12 on 2025/3/25.
|
||||
//
|
||||
#include <solution/lcp_67.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void inorder(struct TreeNode *root)
|
||||
{
|
||||
if (root == NULL)
|
||||
return;
|
||||
inorder(root->left);
|
||||
if (root->left != NULL && root->val != -1)
|
||||
{
|
||||
struct TreeNode *p = root->left;
|
||||
root->left = malloc(sizeof(struct TreeNode));
|
||||
root->left->left = p;
|
||||
root->left->right = NULL;
|
||||
root->left->val = -1;
|
||||
}
|
||||
|
||||
if (root->right != NULL && root->val != -1)
|
||||
{
|
||||
struct TreeNode *p = root->right;
|
||||
root->right = malloc(sizeof(struct TreeNode));
|
||||
root->right->right = p;
|
||||
root->right->left = NULL;
|
||||
root->right->val = -1;
|
||||
}
|
||||
inorder(root->right);
|
||||
}
|
||||
|
||||
struct TreeNode *expandBinaryTree(struct TreeNode *root)
|
||||
{
|
||||
inorder(root);
|
||||
return root;
|
||||
}
|
||||
Reference in New Issue
Block a user