Very concise solution.

I just translate the "Iterative - BFS" into C++ as below :

int longestConsecutive(TreeNode* root)
{
//edge case :
if(root == NULL)
return 0;
//build queue
//pair.first : current node, pair.second : the longest length until current node
queue<pair<TreeNode*, int>> q;
q.push({root, 1});
int longest = 1;
while(!q.empty()){
int cursize = q.size();
//query all neighbours in size of 'cursize'
for(int i = 0; i < cursize; ++i){
TreeNode* cur = q.front().first;
int curlen = q.front().second;
q.pop();
//query left child
if(cur->left != NULL){
if(cur->left->val - 1 == cur->val){
q.push({cur->left, curlen+1});
longest = max(longest, curlen+1);
}
else
q.push({cur->left, 1});
}
//query right child
if(cur->right != NULL){
if(cur->right->val - 1 == cur->val){
q.push({cur->right, curlen+1});
longest = max(longest, curlen+1);
}
else
q.push({cur->right, 1});
}
}//end for
}//end while
return longest;
}