9ms C++ BFS right to left


  • 0
    W
    class Solution {
    public:
        int findBottomLeftValue(TreeNode* root) {
            TreeNode* cur;
            queue<TreeNode*> q;
            q.push(root);
            while(!q.empty()) {
                cur = q.front();
                q.pop();
                if(cur->right) q.push(cur->right);
                if(cur->left) q.push(cur->left);
            }
            return cur->val;
        }
    };
    

Log in to reply
 

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