```
int longestConsecutive(TreeNode* root) {
if(!root) return 0;
return max(longestConsecutive(root->left, root->val, 1), longestConsecutive(root->right, root->val, 1));
}
int longestConsecutive(TreeNode* root, int parentVal, int len) {
if(!root) return len;
if(root->val == parentVal + 1)
len++;
else
len = 1;
return max(len, max(longestConsecutive(root->left, root->val, len), longestConsecutive(root->right, root->val, len)));
}
```