【leetcode】叶子相似的树
bool recursion(struct TreeNode* root, int* arr, int* pst) { if (!root->left && !root->right) { if (!arr[*pst]) { arr[(*pst)++] = root->val; return true; } else { return (arr[(*pst)++] == root->val)? true: false; } } else if (!root->left) return recursion(root->right,arr,pst); else if (!root->right) return recursion(root->left,arr,pst); return recursion(root->left,arr,pst) && recursion(root->right,arr,pst); } bool leafSimilar(struct TreeNode* root1, struct TreeNode* root2){ int arr[1000]={0}; int pst=0,num=0; recursion(root1,arr,&pst); return (recursion(root2,arr,&num) && pst==num)?true : false; }