Maintain max frequency, current count, and pointer to previous node.

```
class Solution {
public:
vector<int> findMode(TreeNode* root) {
vector<int> ans;
if(!root) return ans;
int max_freq = 0, cnt = 0;
TreeNode *prev = NULL;
helper(root, ans, max_freq, prev, cnt);
if(cnt == max_freq) ans.push_back(prev->val);
return ans;
}
private:
void helper(TreeNode *root, vector<int> &ans, int &max_freq, TreeNode *&prev, int &cnt) {
if(!root) return;
helper(root->left, ans, max_freq, prev, cnt);
if(prev && prev->val == root->val) {
if(++cnt > max_freq) ans.clear(), max_freq = cnt;
}
else if(prev && prev->val != root->val) {
if(cnt == max_freq) ans.push_back(prev->val);
cnt = 1;
}
else max_freq = cnt = 1;
prev = root;
helper(root->right, ans, max_freq, prev, cnt);
}
```