straightforward c++ solution


  • 0
    W

    queue<TreeNode*> this_level, last_level;
    this_level.push(root);
    while (!this_level.empty()) {

    	last_level = this_level;
    
    	queue<TreeNode*> next_level;
    	while (!this_level.empty()) {
    
    		TreeNode* node = this_level.front();
    		this_level.pop();
    		if (node->left) next_level.push(node->left);
    		if (node->right) next_level.push(node->right);
    
    	}
    
    	this_level = next_level;
    	
    
    }
    
    return last_level.front()->val;

Log in to reply
 

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