/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
char* map = malloc(sizeof(char) * 100000);
int pf[1] = {};
bool go(struct TreeNode* root)
{
if(root == NULL)return;
map[pf[0]] = '(root->val)' ;
pf[0] ++;
if((root->left != NULL)&&(root->right != NULL))
{
map[pf[0]] = '(';
pf[0] ++;
go(root->left);
map[pf[0]] = ')';
pf[0] ++;
map[pf[0]] = '(';
pf[0] ++;
go(root->right);
map[pf[0]] = ')';
pf[0] ++;
}
else if(root->left != NULL)
{
map[pf[0]] = '(';
pf[0] ++;
go(root->left);
map[pf[0]] = ')';
pf[0] ++;
}
else if(root->right != NULL)
{
map[pf[0]] = '(';
pf[0] ++;
map[pf[0]] = ')';
pf[0] ++;
map[pf[0]] = '(';
pf[0] ++;
go(root->right);
map[pf[0]] = ')';
pf[0] ++;
}
}
char* tree2str(struct TreeNode* root)
{
go(root);
map[pf[0]] = '\0';
pf[0] ++;
return map;
}
今天的每日 為啥會錯
他說我編譯錯誤捏
https://i.imgur.com/ASpoxsY.png