/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<int> result;
int tmpCount = 0, curCount = 0, maxCount = 0;
vector<int> findMode(TreeNode* root) {
findMe(root);
return result;
}
void findMe(TreeNode* tree) {
if (tree == NULL) return;
findMe(tree->left);
tmpCount++;
if (tree->val != curCount) {
curCount = tree->val;
tmpCount = 1;
}
if (tmpCount > maxCount) {
maxCount = tmpCount;
result.clear();
result.push_back(tree->val);
} else if(tmpCount == maxCount) {
result.push_back(tree->val);
}
findMe(tree->right);
}
};