C++ 9ms DFS


  • 0
    L
    class Solution {
    public:
        int findBottomLeftValue(TreeNode* root) {
        	int max_level =1, value = root->val;
        	help(root,max_level,1,value);
        	return value;
        }
    
        void help(TreeNode *node, int &max_level, int cur_level, int &value)
        {
        	if(node->left)
        		help(node->left,max_level,cur_level+1,value);
        	
        	if(node->right)
        		help(node->right,max_level,cur_level+1,value);
        	
        	if(cur_level > max_level)
        	{
        		max_level = cur_level;
        		value = node->val;
        	}
         }
    };
    

Log in to reply
 

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