C++ recursion


  • 0
    A
    public:
        int level;
    
    	int value;
    
    public:
    
    	Solution():level(-1) {}
    
    	void getVal(TreeNode* root, int level) {
    
    		if (!root) return;
    
    		if (root->left != NULL && level > this->level)
    		{
    			value = root->left->val;
    			this->level = level;
    		}
    		
    		if (root->right != NULL && level > this->level)
    		{
    			value = root->right->val;
    			this->level = level;
    		}
    		
    		getVal(root->left, level+1);
    
    		if (root->right != NULL)
    			getVal(root->right, level+1);
    	}
    
    	int findBottomLeftValue(TreeNode* root) {
    
            value = root->val;
    		getVal(root,0);
    		return value;
    	}
    };

Log in to reply
 

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