C++ easy solution Beats 87%

  • 0
    class Solution {
        vector<int> res;
        void help(TreeNode* t, int depth){
            if (!t) return;
            if (res.size()<=depth) res.push_back(t->val);
            else  res[depth] = max(res[depth],t->val);
            help(t->left, depth+1);
            help(t->right, depth+1);
        vector<int> largestValues(TreeNode* root) {
            help(root, 0);
            return res;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.