왼쪽과 잎의 404 재귀 평가

제목 설명
제목 설명

코드

public class Solution {
	public int sumOfLeftLeaves(TreeNode root){
		int sum = 0;
		if(root == null){
			return 0;//这个判断非常重要,若缺失将引发空指针异常
		}
		if(root.left!=null && root.left.left==null && root.left.right == null){
			sum =root.left.val;
		}else{
			sum += sumOfLeftLeaves(root.left);
		}
		sum += sumOfLeftLeaves(root.right);
		return sum;
	}
}

공연
공연

게시 75 개 원래 기사 · 원의 칭찬 0 · 조회수 1511

추천

출처blog.csdn.net/qq_34087914/article/details/104100501