Great solution!

One can think of BFS (level-order traverse) easily, but DFS is not so straight forward as BFS.

Here is the C++ level-order traverse solution

```
/**
* 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> largestValues(TreeNode* root) {
vector<int> ret;
if(!root)
return ret;
queue<TreeNode*> q;
q.push(root);
while(!q.empty()) {
int size = q.size();
int max_val = INT_MIN;
for(int i = 0; i < size; ++i) {
TreeNode* tmp = q.front();
q.pop();
if(tmp->val > max_val)
max_val = tmp->val;
if(tmp->left)
q.push(tmp->left);
if(tmp->right)
q.push(tmp->right);
}
ret.push_back(max_val);
}
return ret;
}
};
```